extjs 3.4无法访问树中节点的子级

extjs 3.4 unable to access children of a node in a tree

本文关键字:节点 访问 extjs      更新时间:2024-03-07

我正在尝试用javascript、JSON数据和extjs构建一种文件资源管理器类型的树结构。我正在使用的JSON数据是

[
{
    "id": "Folder One",
    "text": "<font color='"#000000'" size='"2'"><b>Folder One</b></font>",
    "children": [
        {
            "id": "111",
            "text": "<font color='"#000000'" size='"2'"><b>File1 (111)</b></font>",
            "leaf": true
        }
    ]
},
{
    "id": "Folder Two",
    "text": "<font color='"#000000'" size='"2'"><b>Folder Two</b></font>",
    "children": [
        {
            "id": "111",
            "text": "<font color='"#000000'" size='"2'"><b>File1 (111)</b></font>",
            "leaf": true
        }
    ]
}
]

此JSON通过以下代码传递到Asynctree节点:

var   fileList =   JSON.parse(resp);
    //alert("fileList from Server : "+JSON.stringify(fileList));
asyncTree = new Ext.tree.AsyncTreeNode({
            id:'asyncTree',
            expanded: true,
            border : false,
            children: [
                       {
                           "id":"asyncTreeChild",
                           "text":"<font color=#000000 size=2><b>My Computer</b></font>",
                           children:fileList
                        }
                       ]
        });

问题是节点"文件夹一"下的文件何时不可点击。相反,选择直接移动到"文件夹二"节点下的文件。节点"文件夹一"answers"文件夹二"也返回正确的路径。它只是"文件夹一"下无法访问的文件。有什么想法吗?

我发现了问题所在。。子项的id属性相同,这是导致问题的原因。将其更改为不同的值(从111更改为其他值)解决了这个问题。