4

我正在创建一个 MVC extjs 应用程序。我有一个带有商店的树形面板,它正在从 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 文件中时,此配置有效。但是 id 不起作用,当它们从 php 源加载时。

感谢您的任何回答。

4

2 回答 2

5

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

{
   success: true,
   children: // here is the array of items
}
于 2012-12-21T10:34:15.337 回答
0

您的字段显示 db_name 和 json 响应显示“dbName”。你能检查一下是不是错字?

于 2012-12-19T17:10:47.213 回答