我有一個已經充滿模型的集合,我需要用一個模型更新這個集合並在頁面上顯示它(模型)。所以,下面的文檔,我的觀點得到模型從服務器:骨幹抓取然後渲染模型
this.collection.fetch(
{
add: true,
data: FILTER + '&page=' + (CURRENT_PAGE + 1),
success: function(response){}
});
但這種新模式沒有在網頁上顯示,而是收集得到新模式。我想這個集合的某些方法必須被解僱,但事實並非如此。
對不起提前,新手在主鏈)
的視圖:
var EcoNatureCardInListView = Backbone.View.extend({
tagName: 'tr',
className: 'nature-card-tr',
template: $('#natureCardsListTR').html(),
render: function(){
var tmpl = Handlebars.compile(this.template);
this.$el.html(tmpl(this.model.toJSON()));
return this;
}
});
var EcoNatureCardsListView = Backbone.View.extend({
el: $('#nature-cards-wrapper'),
events: {
"click a.short-eco-entity": "showFullEcoNatureCard",
"click #add-cards": "addCardsOnPage"
},
initialize: function(){
$("#nature-cards-list").html("");
this.collection = new EcoNatureCardCollection();
this.collection.fetch({
success: function(response){}
});
this.collection.on('reset', this.render, this);
this.collection.on('add', this.add, this);
},
render: function(){
var that = this;
_.each(this.collection.models, function(item){
that.renderEcoNatureCard(item);
}, this);
$(addCards).show();
$("#total-objects").text(TOTAL_OBJECTS);
$("#filtered-objects").text(FILTERED_OBJECTS);
if (this.collection.length < 20){
$(addCards).hide();
}
},
renderEcoNatureCard: function(item){
var ecoNatureCardInListView = new EcoNatureCardInListView({
model: item
});
$('#nature-cards-list').append(ecoNatureCardInListView.render().el);
},
showFullEcoNatureCard: function(e){
var _id = $(e.currentTarget).attr('value');
var natureCard = ecoNatureCardsListView.collection.where({ _id: _id })[0];
if (typeof(fullEcoNatureCardView) === 'undefined'){
fullEcoNatureCardView = new FullEcoNatureCardView(natureCard);
} else {
fullEcoNatureCardView.initialize(natureCard);
}
},
addCardsOnPage: function(){
this.collection.fetch({
add: true,
data: FILTER + '&page=' + (CURRENT_PAGE + 1),
success: function(response){}
});
},
filterDocs: function(FILTER){
$("#nature-cards-list").html("");
//$(loading).show();
this.collection.fetch({
data: FILTER,
success: function(response){}
});
}
});
P.S.版本0.9.2
請將您的看法發佈到您使用此係列的地方! – nemesv