for*_*sto 5 javascript collections backbone.js
我需要清空一个集合,按顺序删除每个项目.
this.nodes.each(function(node){
this.nodes.remove(node);
}, this);
Run Code Online (Sandbox Code Playgroud)
不起作用,因为在删除每个节点时,它会更改集合的长度.制作一个临时数组,然后迭代它的工作原理.有没有更好的办法?
尝试一下this.nodes.reset(),除非你需要remove事件。
否则:
var nodes = this.nodes;
while (nodes.length > 0)
nodes.remove(nodes.at(0));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3805 次 |
| 最近记录: |