0

我正在开发一个使用jQuery easy ui的项目

我实现了树节点,但遇到了问题。我想使用拖放功能,但无法生成正确的 json 字符串。

这就是我所拥有的。此数据是从数据库中提取的:

<?php
$array = array( 0 => array( 
                "id"        => 1,
                "text"      => "Root Dir",
                "parent"    => 0
                ),
            1 => array(
                "id"        => 2,
                "text"      => "Folder one",
                "parent"    => 1
                ),
            2 => array(
                "id"        => 3,
                "text"      => "Folder two",
                "parent"    => 2
                ),
            3 => array(
                "id"        => 4,
                "text"      => "File",
                "parent"    => 3
                )
    );
?>

最终输出应如下所示

<?php
$array = array(
    "id"        => 1,
    "text"      => "Root Dir",
    "children"  => array(
            "id"        => 2,
            "text"      => "Folder one",
            "children"  => array(
                    "id"        => 3,
                    "text"      => "Folder one",
                    "children"  => array(
                            "id"    => 4,
                            "text"  => "File"
                        )
                )
        )
);
print json_encode( $array );
?>

如果需要,我愿意调整数据库设计。

4

0 回答 0