Javascript Backbone.js中的事件
你能帮我点击一下吗??这是我的密码Javascript Backbone.js中的事件,javascript,backbone.js,Javascript,Backbone.js,你能帮我点击一下吗??这是我的密码 $(function() { var Trainee = Backbone.Model.extend(); var TraineeColl = Backbone.Collection.extend({ model: Trainee, url: 'name.json' }); var TraineeV
$(function() {
var Trainee = Backbone.Model.extend();
var TraineeColl = Backbone.Collection.extend({
model: Trainee,
url: 'name.json'
});
var TraineeView = Backbone.View.extend({
el: "#area",
template: _.template($('#areaTemplate').html()),
render: function() {
this.model.each(function(trainee){
var areaTemplate = this.template(trainee.toJSON());
$(this.el).append(areaTemplate);
},this);
return this;
}
});
var trainee = new TraineeColl();
var traineeView = new TraineeView({model: trainee});
trainee.fetch();
trainee.bind('reset', function () {
traineeView.render();
});
});
我在(培训生.toJSON)之后的o/p是
o/p一切正常。。。
现在,我想在单击按钮后获得此o/p oly…只需向该按钮添加一个事件即可。因为您使用的是jQuery,所以应该很简单:
$(function () {
$("#your_button_id").on("click", function (e) {
e.preventDefault();
// your code here
});
});
我不明白o/p是什么 无论如何,您可以这样做:
trainee.bind('reset', function () {
$('button').click(function() {
traineeView.render();
});
});
使用适当的jQuery选择器$('button')作为按钮…您希望输出的按钮在哪里?在template?@OP中,您可以在我提供了一个包含下划线的主干模板的基础上起草查询,虽然你必须找到一个从json文件中检索
受训人员的等价物。按钮可以在模板中,我点击它o/p shd进入区域我修改了代码,添加了事件…但是按钮n d o/p会同时显示,而不触发点击的按钮…在我的js代码中,我包括。。。事件:{“click#up”:“render”},在html脚本中,如。。。非常感谢augustin…在我的html脚本中做了某些修改之后,它对我起了作用
trainee.bind('reset', function () {
$('button').click(function() {
traineeView.render();
});
});