我在模板中獲得了Modal Reveal(http://foundation.zurb.com/docs/components/reveal.html),在這種模式下,我得到了一個帶有按鈕的窗體,我想在視圖中聽這個按鈕,但是當我點擊它時不發射任何東西。 這裏是我的代碼:Backbone.js在Modal Reveal中點擊事件
的index.html:
<body>
<div class="page">
<div id="content"></div>
</div>
</body>
tplGroups.html:
<div id="myModal" class="reveal-modal small" data-reveal>
<label>Name :</label>
<input type="text" id="inNameGroup"></input>
<label > Description :</label>
<textarea id="inDescriptionGroup"></textarea>
<button class="button right" id="btnAddGroup">Add group</button>
<a class="close-reveal-modal">×</a>
</div>
<div class="row">
<button class="button tiny right" data-reveal-id="myModal" data-reveal>Add</button>
</div>
group.js:
el: "#content",
initialize: function(){},
render:function(){
this.template = _.template(tpl.get('tplGroup'));
this.$el.html(this.template(this.model.attributes));
this.$el.i18n();
return this;
},
events:{
"click #btnAddGroup": "addGroup"
},
addGroup: function(){
...
}
我認爲問題在於視圖無法在el中找到按鈕。
這是一個清潔的解決方案。謝謝! – codebreaker
基金會6有任何更新嗎?這似乎不再有效。 – user1801879