【问题标题】:Using Remove event to detect the model removed from the collection in Backbone.js使用 Remove 事件检测从 Backbone.js 中的集合中删除的模型
【发布时间】:2013-04-01 18:15:44
【问题描述】:
我的问题是,当我们绑定/监听集合的添加事件时,有没有办法检测从集合中删除的模型。
例如:
this.listenTo(monthsOnBoardCollection, "remove", function(){
//is it possible here to find what got removed from the collection ?
}
【问题讨论】:
标签:
backbone.js
underscore.js
backbone.js-collections
【解决方案1】:
您有 Catalog of Events,它显示正在传递给事件的参数。
"remove" (model, collection, options) — when a model is removed from a collection.
所以基本上是这样的:
this.listenTo(monthsOnBoardCollection, "remove", function(model, collection, options){
//now you have the model, the collection and the options which were passed to the remove method
}