[英]Events in Backbone.js
Can u help with the click event?? 您能帮忙点击事件吗? here is my code.
这是我的代码。
$(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();
});
});
my o/p after(trainee.toJSON) is 我的O / P之后(trainee.toJSON)是
Sinduja
E808514
HPS
Shalini
E808130
HBS
Priya
E808515
HSG
Everything is fine with the o/p... Now i want to get this o/p oly after a button click.... o / p一切都很好...现在,我想在单击按钮后获得此o / p oly。
Simply add an event to that button. 只需向该按钮添加一个事件。 Since you're using jQuery, that should be simple :
由于您使用的是jQuery,因此应该很简单:
$(function () {
$("#your_button_id").on("click", function (e) {
e.preventDefault();
// your code here
});
});
I don't understand what the o/p is... 我不明白什么是O / P ...
Anyway, you can do something like that : 无论如何,您可以执行以下操作:
trainee.bind('reset', function () {
$('button').click(function() {
traineeView.render();
});
});
with the proper jQuery selector $('button') for your button... 为您的按钮使用适当的jQuery选择器$('button')...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.