Ember.js如何从没有ember数据的数组控制器中删除对象 [英] Ember.js how to remove object from array controller without ember data
问题描述
我正在使用jquery ajax删除记录后,更新arraycontroller模型。我可以使用self.pushObject(data)添加一个新对象,但是我无法使用self.removeObject(data)删除对象。有人可以帮忙。 (数据是我删除的对象,服务器在服务器中将其删除后发送回来。)
I am trying to update the arraycontroller model after deleting a record using jquery ajax.I can add a new object using self.pushObject(data), but i cannot remove the object using self.removeObject(data). can someone please help. ("data" is the object that i removed, the server sends it back after removing it in server.)
removeTodo: function(id) {
var page_id = id;
self = this;
Ember.$.ajax({
url: url+id,
type: "DELETE"
}).then(function(data) {
self.removeObject(data);
});
}
推荐答案
数据
可能具有相同的属性,但不是数组中存在的对象。看到这里,这两个对象看起来完全一样,但它们是不同的对象,因此不一样。
data
might have the same properties, but it isn't the object that exists in your array. See here, both of these objects look exactly alike, but they are different objects, and as such aren't equal.
{ foo : 7 } != { foo : 7 }
从集合中删除时,如果您传入要删除的对象,该对象必须存在于集合中。
When removing from a collection, if you pass in the object to be removed, that object must exist in the collection.
您将首先找到该对象,然后将其从集合中删除。
You would want to first find the object, then remove it from the collection.
.then(function(data) {
var obj = self.findBy('id', id); // assuming the object has a property 'id'
self.removeObject(obj);
});
这篇关于Ember.js如何从没有ember数据的数组控制器中删除对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!