无法从json创建ExtJS树 [英] Unable to create ExtJS tree from json
本文介绍了无法从json创建ExtJS树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[
{
root:{
text :Root Node,
expanded:true,
children:[
{
text:Invisible,
leaf :
children:[
{
text:书签2,
leaf:true
},
{
text:书签3,
leaf:true
}
]
},
{
:可见,
leaf:true,
children:[
{
text:书签4,
leaf真
},
{
text:书签5,
叶:true
}
]
}
]
}
}
]
这是我正在使用的代码对于我的商店:
Ext.define('DHT.store.Categories',{
extend:'Ext。 data.TreeStore',
model:'DHT.model.Category',
autoLoad:true,
autoSync:true,
proxy:{
type:'ajax ',
url:'treedata.json',
reader:
{
type:'json'
}
}
}) ;
这里是树的代码:
Ext.define('DHT.view.Category.CategoryList',{
extends:'Ext.tree.Panel',
alias:'widget.treeList ',
width:200,
height:400,
store:Ext.create('DHT.store.Categories'),
rootVisible:false
}) ;
上面的代码只显示不断扩展的文件夹图像!有人可以指出问题吗?
解决方案
-
你有叶:这不可能
{
text:Invisible,
leaf:true ,
children:[
{
text:书签2,
leaf:true
},
...
]
}
正确:
{
text:Invisible,
leaf:false,
children:[
{
text:书签2,
leaf:true
},
...
]
}
-
你必须定义一个 root 属性在您的树木中
-
在您的情况下,根属性需要一致它将是root,children,children
阅读这里:来自JSON的嵌套数据的Treepanel
I am trying to create a tree from json file. The JSON data is:
[
{
"root": {
"text": "Root Node",
"expanded": true,
"children": [
{
"text": "Invisible",
"leaf": true,
"children": [
{
"text": "Bookmark 2",
"leaf": true
},
{
"text": "Bookmark 3",
"leaf": true
}
]
},
{
"text": "Visible",
"leaf": true,
"children": [
{
"text": "Bookmark 4",
"leaf": true
},
{
"text": "Bookmark 5",
"leaf": true
}
]
}
]
}
}
]
Here is the code I am using for my store:
Ext.define('DHT.store.Categories', {
extend: 'Ext.data.TreeStore',
model: 'DHT.model.Category',
autoLoad: true,
autoSync: true,
proxy: {
type: 'ajax',
url: 'treedata.json',
reader:
{
type: 'json'
}
}
});
and here is the code for tree:
Ext.define('DHT.view.Category.CategoryList', {
extend: 'Ext.tree.Panel',
alias: 'widget.treeList',
width: 200,
height: 400,
store: Ext.create('DHT.store.Categories'),
rootVisible: false
});
The above code is only showing folder image that keep on expanding! Can someone point out the problem?
解决方案
You have leaf: true and children, this is not possible
{ "text": "Invisible", "leaf": true, "children": [ { "text": "Bookmark 2", "leaf": true }, ... ] }
correct:
{ "text": "Invisible", "leaf": false, "children": [ { "text": "Bookmark 2", "leaf": true }, ... ] }
You have to define a root property in your treestore
The root property needs to be consistent, in your case it would be 'root', 'children', 'children'
Read this: Treepanel with nested data from JSON
这篇关于无法从json创建ExtJS树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文