在尝试随机化集合中对象的顺序时,我遇到了一些问题。
下面是我尝试过的代码:
console.log(this.collection);
shuffled = this.collection.shuffle();
console.log(shuffled);
下面是控制台输出(使用包含3个项目的测试集合):
child {models: Array[3], length: 3, _byId: Object, url: "/myurl/myid", _listenerId: "l7"…}
_byId: Object
_events: Object
_idAttr: "id"
_listenerId: "l7"
length: 3
models: Array[3]
__proto__: Surrogate
[child, child, child]
0: child
1: child
2: child
length: 3
__proto__: Array[0]
正如你所看到的,Collection没有被正确地混洗,相反,它创建了一个新的不可用的对象,里面充满了讨厌的孩子。
我所要做的就是在将模型传递给视图进行显示之前,对模型在集合中出现的顺序进行随机化(我正在创建一个名为“随机化”的按钮,它需要随机化集合中项目的显示)。我认为这将是一项简单的任务,但在这一点上,我正在考虑只创建一个全新的模型,并在服务器上进行混洗。
任何帮助都是非常感谢的!
发布于 2013-05-26 13:43:08
console.log(this.collection);
this.collection.reset(this.collection.shuffle(), {silent:true});
console.log(this.collection);
https://stackoverflow.com/questions/16754948
复制相似问题