https://bbs.csdn.net/topics/390481685?page=1 function convert(source){ var tmp={},parent,n; for (n in source){ var item=source[n]; if (item.ID==item.ParentID){ parent=item.ID; } if (!tmp[item.ID]){ tmp[item.ID]={}; } tmp[item.ID].Name=item.Name; tmp[item.ID].ID=item.ID; if (!( "children" in tmp[item.ID]))tmp[item.ID].children=[]; if (item.ID!=item.ParentID){ if (tmp[item.ParentID]){ tmp[item.ParentID].children.push(tmp[item.ID]); } else { tmp[item.ParentID]={children:[tmp[item.ID]]}; } } } return tmp[parent]; }