我要創建使用backbone.js.Below事件是我js代碼Backbone.js的事件懷疑
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(good){
var areaTemplate = this.template(good.toJSON());
$('body').append(areaTemplate);
},this);
return this;
}
});
var good = new TraineeColl();
var traineeView = new TraineeView({model: good});
good.fetch();
good.bind('reset', function() {
$('#myButtons').click(function() {
traineeView.render();
});
});
<div class = "area"></div>
<div class="button" id="myButtons">
<button class="firstbutton" id="newbutton">
Display
</button>
</div>
<script id="areaTemplate" type="text/template">
<div class="name">
<%= name %>
</div>
<div class="eid">
<%= eid %>
</div>
<div class="subdomain">
<%= subdomain %>
</div>
上點擊顯示按鈕我的O/P是 顯示//這是一個按鈕//
辛杜嘉 E808514 HPS
Shalini E808130 HBS
普里亞 E808515 HSG
從現在的觀點,我必須改變事件綁定到模型中的model..the更改必須到顯示器上顯示點擊按鈕輸出的觀看而觸發。
當模型改變時,你想顯示(點擊顯示按鈕)所有的模型或只是改變的模型? – 2013-02-20 14:43:39