tou*_*sif 0 backbone.js marionette
这是我正在创建树结构的代码compositeView片段.
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++;
}
});
Run Code Online (Sandbox Code Playgroud)
树变得完美但事件没有被绑定或没有被触发.永远不会调用Show方法.我正在使用Backbone.Marionette v0.9.1
您将视图本身设置为使用menuItemcss类进行渲染.在任何骨干视图中(这不是特定于Marionette),如果要直接处理视图元素上的事件(不是其中一个子元素),则指定不带选择器的事件.
在你的情况下,它将是:
events: {
"click": "show"
}
Run Code Online (Sandbox Code Playgroud)
这将el直接使用"click"事件配置视图,并且show当您单击此视图的HTML的任何部分时将调用该方法.
| 归档时间: |
|
| 查看次数: |
2943 次 |
| 最近记录: |