Backbone视图知识 delegateEvents用法案例
时间:2014-04-08 06:26 来源: 我爱IT技术网 作者:微风
Backbone视图知识
delegateEvents
例子1
html:
<divid="jimvinDiv"></div> <!--以下为Underscore模板--> <scripttype="text/template" id="item-template"> <divclass="view"> <inputclass="toggle" type="checkbox" <%=completed ? 'checked' : '' %> > <label><%-title %></label> <buttonclass="destroy"></button> </div> </script>
var ItemView =Backbone.View.extend({
template:_.template($('#item-template').html())
,render:function() {
this.$el.html(this.template({completed: true, title: 'myTitle' })); // this.model.attributes
return this;
}
,el:'#jimvinDiv'
,events: {
"click.destroy": "click"
}
,click:function(){
alert('click');
}
});
itemView = newItemView();
itemView.render();
//点击button.destroy的时候,触发click事件处理器
本文来源 我爱IT技术网 http://www.52ij.com/jishu/4830.html 转载请保留链接。
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
