我有一个要管理的“条目”列表。列表显示在屏幕的下半部分,而输入表单显示在页面的顶部。 每个条目都包含“entryDate”属性。创建时重新获取主干集合
该列表绑定到选定的“月”期间(例如2014年8月),它仅显示所选日期范围之间的条目。这些条目也分页。我显示每页X条目,无限滚动。列表的排序顺序在entryDate上递减,最近的条目首先显示。
如果entryDate总是currentDate,我可以在列表中添加新行,而无需重新渲染整个事物,但事实并非如此。我认为检查输入的日期是否包含在选定的时间段内,或者不是,只是为了知道是否需要重新加载列表。
现在,我想通过在每次成功插入时获取/重置列表来简化操作。但是......我做不到。
一个从我的观点代码片段:
initialize: function() {
this.collection = new EntriesCollection();
this.fetchTransactions();
this.listenTo(this.collection, 'reset', this.render);
this.listenTo(this.collection, 'add', this.fetchTransactions);
this.rowViews = [];
this.render();
},
fetchTransactions: function() {
this.collection.fetch({ reset:true });
},
addEntry: function() { // on form submit
var entryData = {};
// load data from form...
this.collection.create(entryData);
},
这并不正常工作,列表不会再牵强。
'add'收集事件应该在提取之前还是之后触发?搞清楚事件时/当他们开火是只要登录他们全力以赴
this.listenTo(this.collection, 'reset', this.render);
与
this.listenTo(this.collection, 'sync', this.render);
您可以添加将新模型添加到集合的代码吗? – 2014-09-10 21:07:34
它只是this.collection.create(entryData); – 2014-09-10 21:08:16
也许你可以在创建 – 2014-09-10 21:34:53