Extjs树面板未加载json数据

Extjs tree panel not loading json data

本文关键字:加载 json 数据 Extjs      更新时间:2024-02-21

嗨,我正在尝试通过json和
为树面板加载数据我指的是这个链接。树面板显示正常,只是并没有数据。

这是我的代码
编辑更新的代码作为Objectone建议的

Ext.require([
'Ext.tree.*',
'Ext.data.*',
'Ext.tip.*'
]);
Ext.onReady(function() {
var store = Ext.create('Ext.data.TreeStore', {
    proxy: {
        type: 'ajax',
        url: 'treeJson.json'
    },      
    root: {
        expanded: true
    },
    folderSort: true,
    sorters: [{
        property: 'text',
        direction: 'ASC'
    }]
});
var tree = Ext.create('Ext.tree.Panel', {
    store: store,
    renderTo: 'tree-div',
    height: 300,
    width: 250,
    title: 'Files',
    useArrows: true,
    dockedItems: [{
        xtype: 'toolbar',
        items: [{
            text: 'Expand All',
            handler: function(){
                tree.expandAll();
            }
        }, {
            text: 'Collapse All',
            handler: function(){
                tree.collapseAll();
            }
        }]
    }]
});
console.log(store.getRootNode());
});

这是json

[
   {
    "text": "To Do",
    "cls": "folder",
    "expanded": true,
    "children": [
        {
            "text": "Go jogging",
            "leaf": true
        },
        {
            "text": "Take a nap",
            "leaf": true
        },
        {
            "text": "Climb Everest",
            "leaf": true
        }
    ]
}
]

Firebug没有显示错误,
知道我做错了什么吗?

提前感谢

在您的存储中,您提到根id为src,但您的json没有src的id。

在示例链接中,JSON如下,id被提到为"src/fx",其中src是根

{text:fx, id:src/fx, cls:folder, qtip:Type: Folder<br />Last Modified: Jul 9, 2013, 3:24 am}

要让你的东西工作,只需从根中删除id

var store = Ext.create('Ext.data.TreeStore', {
    proxy: {
        type: 'ajax',
        url: 'treeJson.json'
    },      
    root: {
        expanded: true
    },
    folderSort: true,
    sorters: [{
        property: 'text',
        direction: 'ASC'
    }]
});