主干插入位置和位移模型

时间:2013-10-15 11:19:41

标签: javascript backbone.js

是否有一种简单的方法可以在集合的位置插入模型并将所有模型(包括指定索引处的模型)移回,所以基本上将模型“滑动”到某个位置的集合中?

2 个答案:

答案 0 :(得分:2)

可以使用方法.add()并使用传递选项{at: index}在指定索引处插入集合:

myCollection.add(myModel, {at: 14});

同样,对于问题的第二部分,还有相应的方法,例如.slice()

我打赌你可以找到documentation中最合适的一个。

答案 1 :(得分:1)

来自:the docs

Pass {at: index} to splice the model into the collection at the specified index.