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 ......当我点击按钮(有约翰的名字)它应该显示它的味精......