【发布时间】:2018-08-05 09:10:10
【问题描述】:
我有一个如下所示的对象,
我正在尝试基于父子关系改造对象结构。
var b = [];
for(var i=0;i<a.length;i++){
if(a[i].parent == null){
const children = a.filter(x => a[i].parent == null && a[i].id == x.parent);
b.push({'name':a[i].name,'type':'grandparent','children':children})
}
}
我存档了祖父母和孩子,但卡在了子孩子中。
【问题讨论】:
-
I have a JSON- 不,你有一个 javascript 对象...... JSON 从来没有var x =... jSON 是一个对象的字符串表示......所以,你根本没有 JSON ...只是一个普通的 ol' javascript 对象 ...I am trying to reform the JSON structure based on parent and child relationship.- 请显示实际的预期输出,而不是一些只有你才能理解的晦涩表示
标签: javascript jquery arrays angularjs json