var ListView = Backbone.View.extend({
el: $('hello'),
events: {
'click .myName': 'namefunc',
},
initialize: function() {
var stuff = new FieldCollection();
stuff.parse();
var self = this;
stuff.fetch({
success: function (collection, response) {
console.log(response);
self.render(response);
return response;
}
});
},
render:function(output){
_.each(output, function(i){
p=i.name;
$(this.el).append("<button class='myName'>"+p+"</button><h1>"+i.img+"</h1><br/>");
},this);
},
namefunc:function(){
alert('hiii');
}
如何綁定的變化與對誰按下按鈕的人的細節警報的HIII輸出...骨幹+結合
{
"name": "john",
"img": "john.jpg",
"loc": "delhi",
"msg": "hello there"
}
這是即時得到的JSON .. ..when我點擊按鈕(有約翰的名字)應該顯示其味精....
你能解釋一下這個問題比較好? – fguillen
看看這個[post] [1]。所有你需要的 [1]:http://stackoverflow.com/questions/5270188/backbone-js-event-binding – schacki
@fguillen現在檢查 –