所以,我不确定我是否完全理解应如何触发此回调。如果您采用准系统模型,集合和视图:
PatchModel = Backbone.Model.extend({});
PatchCollection = Backbone.Collection.extend({model: PatchModel});
PatchView = Backbone.Marionette.ItemView.extend({template:'#patchview'});
PatchCollectionView = Backbone.Marionette.CollectionView.extend({
itemView:PatchView
,onItemAdded: function(itemView){
console.log("item was added");
}
});
并像这样实例化它们:
Patch0 = new PatchModel({});
Patch1 = new PatchModel({});
Patches = new PatchCollection();
PatchesView = new PatchCollectionView({collection:Patches,el:"dom_id"});
Patches.add(Patch0);
PatchesView.render();
Patches.add(Patch1);
PatchesView onItemAdded回调永远不会触发。嗯...
答案 0 :(得分:3)
看起来文档已经过时了。您应该使用 onAfterItemAdded 或 onBeforeItemAdded
在v1.0.0-rc2
中已更改* BREAKING:* 将
item:added
事件更改为before:item:added
和after:item:added
这是你的例子重新设计的小提琴。 http://jsfiddle.net/puleos/axJg4/
var PatchCollectionView = Backbone.Marionette.CollectionView.extend({
itemView: PatchView,
initialize: function() {
_.bindAll(this);
},
onAfterItemAdded: function(itemView){
console.log("item was added");
},
onRender: function(){
console.log("render");
}
});