gpt4 book ai didi

marionette - 将模型添加到 Marionette CollectionView 的集合中不会触发 onItemAdd 回调

转载 作者:行者123 更新时间:2023-12-01 12:45:44 26 4
gpt4 key购买 nike

因此,我不确定我是否完全理解应该如何触发此回调。如果您采用准系统模型、集合和 View :

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 回调永远不会触发。嗯……

最佳答案

看起来文档已经过时了。您应该使用 onAfterItemAddedonBeforeItemAdded

这在 v1.0.0-rc2 中已更改

*BREAKING: * Changed the item:added event to before:item:added and after:item:added

Link

这是对您的示例进行了修改的 fiddle 。 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");
}
});

关于marionette - 将模型添加到 Marionette CollectionView 的集合中不会触发 onItemAdd 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16180159/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com