Extjs如何将JSON文件夹结构加载到树中?

时间:2015-05-21 12:53:15

标签: javascript json extjs extjs5

我正在尝试使用JSON数据创建Extjs树。我想要加载到树中的数据包含文件夹结构。但是当我试图将数据加载到树中时,它没有显示任何内容。

我已经检查了错误的json代码here (JSONLint),但是每个人看起来都很好。可能会说问题可能出在extjs部分。

我不知道如何让它发挥作用。

我创建了一个像这样的JSON对象:

{
"folders": [
    {
        "name": "Function",
        "id": "workspace://SpacesStore/000-000-000",
        "folders": [
            {
                "name": "Evaluation reports",
                "id": "workspace://SpacesStore/00-00-4949-9caf-6655fg"
            },
            {
                "name": "Function Reports",
                "id": "workspace://SpacesStore/554gg-563-sd555-872e-0098hhjf"
            },
            {
                "name": "Training(POP)",
                "id": "workspace://SpacesStore/4334g-67hj-4357-ba96-4343fhj343"
            }
        ]
    },
    {
        "name": "Application data",
        "id": "workspace://SpacesStore/3434gg-a761-48a2-83fa-3434f454hu",
        "folders": [
            {
                "name": "Application letters",
                "id": "workspace://SpacesStore/23232ff-c95f-4999-sdsd556-00886ggh7765"
            }
        ]
    }
]
}

这是我要加载JSON数据的Extjs部分:

initComponent: function() {

    // declare a new store and load tree data 
    this.store = new Ext.data.TreeStore({
        // set params
        proxy: {
            type: 'ajax',
            reader: 'json',
            url: 'http://localhost:8080/testApp/rest/folder/1'
        }
    });

    this.items = [{
        flex: 1
    }];
    this.callParent();
}

1 个答案:

答案 0 :(得分:1)

您没有告诉读者要阅读的内容:

reader: {
    type: 'json',
    rootProperty: 'folders'
}