Destroying a Backbone Model in a Collection in one step?

后端 未结 2 1612
既然无缘
既然无缘 2021-02-05 07:13

Are these two steps mandatory to delete a Model?

var model = collection.get(id);
model.destroy();
collection.remove(model);

Isn\'t there a way

2条回答
  •  轮回少年
    2021-02-05 07:36

    Model.bind("remove", function() {
      this.destroy();
    });
    ...
    var model = new Model();
    ...
    collection.remove(model);
    

    Removing a model from a collection triggers the "remove" event.

    So if you want to, you can get models to bind to them and destroy themselves.

提交回复
热议问题