一步销毁集合中的主干模型? [英] Destroying a Backbone Model in a Collection in one step?
本文介绍了一步销毁集合中的主干模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
删除模型是否必须执行这两个步骤?
Are these two steps mandatory to delete a Model?
var model = collection.get(id);
model.destroy();
collection.remove(model);
当模型从集合中移除时,没有办法销毁模型吗?
Isn't there a way to destroy a model when it is removed from its collection?
推荐答案
Model.bind("remove", function() {
this.destroy();
});
...
var model = new Model();
...
collection.remove(model);
从集合中移除模型会触发 "remove"
事件.
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.
这篇关于一步销毁集合中的主干模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文