我有一個Backbone應用程序,其中顯示基於JSON數據的模型集合。在JSON數據內部,我有endDate
- 它給了我實時的日期。它基於競爭模塊。我想要實現的是,如果給定的日期已經過期,我想隱藏(甚至可能刪除)集合中的模型,這樣競爭就不再可用。BackboneJS當日期已過期時隱藏模型
到目前爲止,我competition.js,在底部的模式是這樣的:
Competition.View = Backbone.View.extend({
tagName: 'ul',
template: 'competition',
initialize: function() {
this.listenTo(this.model, 'sync', this.render);
},
serialize: function() {
return this.model.toJSON();
}
});
Competition.CompetitionModel = Backbone.Model.extend({
url: function() {
return App.APIO + '/i/contests';
},
comparator: function(item) {
return item.get('endDate');
},
defaults: {
"data": []
}
});
然後我的主模塊中,我導入competition.js,這裏我取模型,並使其在特定HTML元素(不知道它需要複製/粘貼在這裏爲我原來的問題):
function (App, Backbone, Competition) {
var CompetitionOverview = App.module();
CompetitionOverview.View = Backbone.View.extend({
template: 'competitionOverview',
initialize: function(){
this.render();
},
beforeRender: function() {
var competitionModel = new Competition.CompetitionModel();
this.insertView('.singleComp', new Competition.View({model: competitionModel}));
competitionModel.fetch();
},
});
return CompetitionOverview;
}
所以,我怎樣才能實現隱藏/刪除該日期已經過期的模型?
在此先感謝...
如果下面的答案幫你解決這個問題,請接受的答案。謝謝。 – jorrebor