Adding object to a Collection in the first position with backbone?

耗尽温柔 提交于 2019-12-20 04:26:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!