我需要一个 JS 循环来将对象数组更改为 json 对象。这是对象的示例数组:
var employees= [
{name:"Jeff",manager:null,title:"The Pres"},
{name:"Amy",manager:"Aaron",title:"lll"},
{name:"Chris",manager:"Aaron",title:"lll"},
{name:"Dana",manager:"Aaron",title:"lll"},
{name:"Joe",manager:"Aaron",title:"lll"},
{name:"Mike",manager:"Aaron",title:"lll"},
{name:"Aaron",manager:"Jeff",title:"lll"}
];
这是预期的 json 对象:
var json = {
name:"Jeff",
title:"The Pres",
children:[{
name:"Aaron",
title:"some title",
children[
{name:"Amy",title:"some title",children[]},
{name:"Chris",title:"some title",children:[]},
{name:"Dana",title:"some title",children:[]},
{name:"Joe",title:"some title",children:[]},
{name:"Mike",title:"some title",children:[]
}]
}]
};
但它超出了我的范围。