我正在尝试遍历Ember-Data异步记录树。当孩子[i]没有孩子时,第5行的功能崩溃。如何验证儿童是否存在儿童[i]?或者你能提供更好的迭代功能吗?
traverse: function(scsLink) {
console.log(scsLink.id);
scsLink.get('children').then(children => {
for(var i in children) {
children[i].get('children').then(_children => {
this.traverse(children[i]);
});
}
});
},
答案 0 :(得分:0)
我能够使用此功能遍历树:
traverse: function(scsLink) {
console.log(scsLink.id);
this.get('scsLinkArr').pushObject(scsLink)
scsLink.get('children').then(children => {
children.forEach((child,index) => {
this.traverse(child);
});
});
},