Destroying a Backbone Model in a Collection in one step?

后端 未结 2 1581
既然无缘
既然无缘 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.

    0 讨论(0)
  • 2021-02-05 07:48

    Calling collection.reset() without passing any models as arguments will empty the entire collection.

    http://backbonejs.org/#Collection-reset

    0 讨论(0)
提交回复
热议问题