问题
I have this simple function to add a Folder to a collection called 'Folders'.
folderAdded: function(folder) {
this.folders.add(folder);
this.$el.empty();
this.render();
}
By default this will add the object in the first position, so it will appear the first one. As my query is order by created, if I refresh the page, the object will go the first place.
How can I add the object at the beginning of the collection?
回答1:
You can use unshift method of the collection.
Add a model at the beginning of a collection. Takes the same options as add
来源:https://stackoverflow.com/questions/36573664/adding-object-to-a-collection-in-the-first-position-with-backbone