extjs treestore with proxy

心不动则不痛 提交于 2019-12-10 09:26:34

问题


I'm creating a MVC extjs application. I've got a treepanel with a store, which is loading the data from a php source. I get the following json-formatted response:

[
{
    "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"
        }
    ]
}
]

My store:

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

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


});

And model:

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'}
],

});

This configuration works, when the data are saved in a .json file. But id doesn't work, when they are loaded from a php source.

Thanks for any answer.


回答1:


The server response must look like this:

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



回答2:


Your field says db_name and json response says 'dbName'. Is it a typo can you check?



来源:https://stackoverflow.com/questions/13952140/extjs-treestore-with-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!