我的数据库吐出这样的数据层次结构数组:
Array(
[0] => array(
[level] => 0
[wo_number] => foo1
[parent] => NULL
)
[1] => array(
[level] => 1
[wo_number] => foo2
[parent] => foo1
)
[2] => array(
[level] => 2
[wo_number] => bar1
[parent] => foo2
)
[3] => array(
[level] => 2
[wo_number] => bar2
[parent] => foo2
)
[4] => array(
[level] => 2
[wo_number] => bar3
[parent] => foo2
)
[5] => array(
[level] => 2
[wo_number] => bar4
[parent] => foo2
)
[6] => array(
[level] => 2
[wo_number] => bar5
[parent] => foo2
)
)
每个数组节点都有一个父键,它引用数组中的另一个节点。
我需要将数组转换为如下格式:
Array(
[0] => array(
[level] => 0
[wo_number] => foo1
[parent] => NULL
[children] => array(
[0] => array(
[level] => 1
[wo_number] => foo2
[parent] => foo1
[children] => array(
etc etc etc
)
)
)
)
)
这样我就可以对其进行 json_encode 编码,并在 ExtJS TreePanel 中使用它。