将对象添加到带有主干的第一个位置的集合中? [英] Adding object to a Collection in the first position with backbone?

查看:16
本文介绍了将对象添加到带有主干的第一个位置的集合中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的函数可以将文件夹添加到名为文件夹"的集合中.

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.

如何在集合的开头添加对象?

推荐答案

您可以使用 unshift集合的方法.

You can use unshift method of the collection.

在集合的开头添加模型.采用与 add

Add a model at the beginning of a collection. Takes the same options as add

这篇关于将对象添加到带有主干的第一个位置的集合中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆