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です....ボタン(ジョン名を持つ)をクリックすると、そのメッセージが表示されます...。