2012-12-19 84 views
4

我正在創建一個MVC extjs應用程序。我有一個商店的treepanel,它正在加載來自php源的數據。 我得到以下JSON格式的響應:extjs treestore與代理

[ 
{ 
    "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不起作用。

感謝您的任何答案。

回答

4

服務器響應必須看起來像這樣:

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

您的字段說db_name和json響應說'dbName'。你可以檢查一下嗎?

+0

感謝答覆。 這是一個錯誤,但它仍然不起作用 – sveatlo

+0

數據來自不同的域/任何代理重定向請求?只要嘗試將代理類型更改爲'jsonp'並查看以排除任何疑問。 – srknori