带代理的extjs treestore

时间:2012-12-19 12:06:04

标签: extjs store models treepanel

我正在创建一个MVC extjs应用程序。我有一个带有商店的treepanel,它正在从php源加载数据。 我得到以下json格式的响应:

[
{
    "text": "Home",
    "leaf": true,
    "dbName": "NULL",
    "children": []
},
{
    "text": "Moje Firma s.r.o.",
    "leaf": false,
    "expanded": false,
    "children": [
        {
            "text": "Vydane",
            "leaf": true,
            "dbName": "demo"
        },
        {
            "text": "Prijate",
            "leaf": true,
            "dbName": "demo"
        }
    ]
},
{
    "text": "Já Živnostník",
    "leaf": false,
    "expanded": false,
    "children": [
        {
            "text": "Vydane",
            "leaf": true,
            "dbName": "demo_de"
        },
        {
            "text": "Prijate",
            "leaf": true,
            "dbName": "demo_de"
        }
    ]
},
{
    "text": "Nezisková organizace",
    "leaf": false,
    "expanded": false,
    "children": [
        {
            "text": "Vydane",
            "leaf": true,
            "dbName": "demo_neziskova"
        },
        {
            "text": "Prijate",
            "leaf": true,
            "dbName": "demo_neziskova"
        }
    ]
},
{
    "text": "Příspěvková organizace",
    "leaf": false,
    "expanded": false,
    "children": [
        {
            "text": "Vydane",
            "leaf": true,
            "dbName": "demo_prispevkovka"
        },
        {
            "text": "Prijate",
            "leaf": true,
            "dbName": "demo_prispevkovka"
        }
    ]
},
{
    "text": "Moje Firma SK s.r.o.",
    "leaf": false,
    "expanded": false,
    "children": [
        {
            "text": "Vydane",
            "leaf": true,
            "dbName": "demo_sk"
        },
        {
            "text": "Prijate",
            "leaf": true,
            "dbName": "demo_sk"
        }
    ]
}
]

我的商店:

Ext.define('Statistics.store.Menu', {
extend: 'Ext.data.TreeStore',
model: 'Menu',
autoLoad: true,
autoSync: true,

proxy   : {
    type : 'ajax',
    url  : 'data.json',
    reader: {
        type: 'json'
    }
}


});

模特:

Ext.define('Statistics.model.Menu', {
extend: 'Ext.data.Model',

fields: [
    {name: 'text', type: 'string'},
    {name: 'leaf', type: 'boolean'},
    {name: 'expanded', type: 'boolean', defaultValue: false},
    {name: 'dbName', type: 'string', defaultValue: 'NULL'}
],

});

当数据保存在.json文件中时,此配置有效。但是当它们从php源加载时,id不起作用。

感谢您的回答。

2 个答案:

答案 0 :(得分:5)

服务器响应必须如下所示:

{
   success: true,
   children: // here is the array of items
}

答案 1 :(得分:0)

你的字段说db_name和json响应说'dbName'。这是一个错字吗?