問題描述
將對象添加到具有主幹的第一個位置的集合中? (Adding object to a Collection in the first position with backbone?)
我有一個簡單的函數可以將文件夾添加到名為“文件夾”的集合中。
folderAdded: function(folder) {
this.folders.add(folder);
this.$el.empty();
this.render();
}
默認情況下,這會將對象添加到第一個位置,因此它會出現在第一個位置。由於我的查詢是按創建順序排列的,如果我刷新頁面,對象將排在第一位。
如何在集合的開頭添加對象?
參考解法
方法 1:
You can use unshift
method of the collection.
Add a model at the beginning of a collection. Takes the same options as add