Ember.js how to remove object from array controller without ember data

梦想的初衷 提交于 2020-01-24 18:36:46

问题


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);
        });
    }

回答1:


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);
});


来源:https://stackoverflow.com/questions/27454228/ember-js-how-to-remove-object-from-array-controller-without-ember-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!