JSON 데이터를 기반으로 모델 컬렉션을 표시하는 백본 앱이 있습니다. JSON 데이터 안에는 endDate
이 있는데 실시간 데이터를 제공합니다. 경쟁 모듈을 기반으로합니다. 내가 원하는 것은 주어진 날짜가 만료 되었다면 콜렉션에서 Model을 숨기거나 (심지어 제거 할 수도 있기 때문에) 경쟁이 더 이상 가능하지 않다는 것입니다.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