0

iam 使用 zTree jquery 插件,该插件需要特定的数组对象结构,如下所示:

    var zNodes =[
        {id:1, title:"No right-click menu 1", open:true, noR:true,
            children:[
                   {id:11, title:"Leaf Node 1-1", noR:true},
                   {id:12, title:"Leaf Node 1-2", noR:true}

            ]},
        {id:2, title:"Right-click 2", open:true,
            children:[
                   {id:21, title:"Leaf Node 2-1"},
                   {id:22, title:"Leaf Node 2-2"},
                   {id:23, title:"Leaf Node 2-3"},
                   {id:24, title:"Leaf Node 2-4"}
            ]},
        {id:3, title:"Right-click 3", open:true,
            children:[
                   {id:31, title:"Leaf Node 3-1"},
                   {id:32, title:"Leaf Node 3-2"},
                   {id:33, title:"Leaf Node 3-3"},
                   {id:34, title:"Leaf Node 3-4"}
            ]}
    ];

如您所见,它是数组和对象的混合,当来自 php 的 i (json_encode) 一切都变成对象时,我需要一个递归函数将“子项”从对象转换为数组,但不是子项的其他内容,除了子项的子项儿童等

编辑 :

更多关于这个主题:http: //jsfiddle.net/0mf78w4r/1/

解决了:

http://jsfiddle.net/0mf78w4r/2/

4

0 回答 0