我已经做了很多寻找答案和测试的,但似乎无法得到TreePanel中在我的显示JSON树数据我正在主视图。我希望有人能说出我做错了或没有正确使用的东西。ExtJS5加载JSON到TreePanel中
这里是我的代码:
Tree.json
{
"message": "SUCCESS",
"details": {
"text": "Categories",
"expanded": "true",
"leaf": "false",
"children": [
{
"text": "Child 1",
"leaf": "true"
},
{
"text": "Child 2",
"leaf": "true"
},
{
"text": "Child 3",
"expanded": "true",
"leaf": "false",
"children": [
{
"text": "Grandchild",
"leaf": "true"
}
]
}
]
}
}
Model.js
Ext.define('MyApp.model.Model',{
extend: 'Ext.data.TreeModel',
requires: ['Ext.data.Field'],
fields:['text']
});
Models.js
Ext.define('MyApp.store.Models',{
extend: 'Ext.data.TreeStore',
alias: 'store.models',
model: 'MyApp.model.Model',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'data/Tree.json',
reader: {
type: 'json',
rootProperty: 'details'
}
});
View.js(摘录)
xtype: 'treepanel',
maxWidth: 300,
minWidth: 150,
store: {
type: 'models',
},
rootVisible: false
在我看来,我看到一个空的树。当我将rootProperty设置为'details'时,Chrome的Developer Tools和Firebug中的Network选项卡显示无限请求我的json,但没有加载到视图中。
任何指向我正确的方向将是非常有益的!因为语法看起来都是正确的,所以我想不出任何我错了,所以我已经走到了死胡同。
谢谢!
编辑:当我在视图中创建内嵌存储时,我能够加载json数据,但不能从单独的store.js文件中加载。我也改变了存储库初始化像这样:
store: Ext.create('Ext.data.TreeStore',{
fields:['name', 'description'],
proxy: {
type: 'ajax',
url: 'data/Categories.json',
reader: {
type: 'json',
rootProperty: 'children'
}
},
}
我也改变了我的JSON的字段从“细节”,以“孩子”,这是能够显示。这可能不会与我的要求相匹配,但我会采取我现在可以获得的内容(与我想要的和内联商店创建不同的JSON格式)。
任何进一步的帮助,将不胜感激!