这是我用来创建树结构的代码复合视图片段。
var TreeView = Backbone.Marionette.CompositeView.extend({
template: "#filterTemplate",
className:"menuItem",
tagName: "ul",
initialize: function(){
this.collection = this.model.type;
counter=0;
},
events: {
'click .menuItem': 'show'
},
show: function(event) {
var target = $(event.target);
console.log(target);
},
appendHtml: function(collectionView, itemView){
// ensure we nest the child list inside of
// the current list item
$(itemView.el).attr("id","innerMenu"+counter);
$(itemView.el).attr("class","innerMenu");
collectionView.$("li:first").append(itemView.el);
counter++;
}
});
树呈现完美,但事件未绑定或未触发。永远不会调用 Show 方法。我正在使用 Backbone.Marionette v0.9.1