【发布时间】:2012-08-05 14:36:17
【问题描述】:
我的代码看起来像这样,但存储/树中没有数据。
JSON 存储有效吗?我需要在 JSON 上添加root 吗?
必须在树面板中定义哪些列?
JSON:
{
"status" : {
"status" : 0,
"msg" : "Ok",
"protocolversion" : "1.1.json"
},
"value" : {
"name" : "Root",
"path" : "\/",
"leaf" : false,
"children" : [
{
"name" : "subfolder1",
"path" : "\/subfolder1",
"leaf" : false,
"children" : []
},
{
"name" : "subfolder2",
"path" : "\/subfolder2",
"leaf" : false,
"children" : []
},
{
"name" : "report1",
"path" : "\/report1",
"leaf" : true,
"children" : []
}
]
}
}
我的 ExtJs 代码:
型号:
// Model for store
var oModel = Ext.define('TreeModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'name', type: 'string' },
{ name: 'path', type: 'string' }
]
});
商店:
// Store with local proxy
var oStore = Ext.create('Ext.data.TreeStore', {
model: oModel,
autoLoad: true,
proxy: {
type : 'ajax',
url : './data/response.json'
},
reader: {
type : 'json',
root : 'value'
}
});
树形面板:
// View with TreePanel
var oTreePanel = Ext.create( 'Ext.tree.Panel', {
store : oStore,
useArrows : true,
displayField: 'text',
rootVisible : true,
multiSelect : true,
border : 0,
columns : [
{
xtype : 'treecolumn',
dataIndex: 'name',
text : 'Tree',
flex : 3
},
{
dataIndex: 'path',
text : 'Path',
flex : 2
}
]
} );
【问题讨论】:
-
对我来说几乎所有东西都不错,但是 root 和 children 属性需要相同,所以我首先将您的 json 响应中的
value更改为children,并定义 root您的读者为children。让我知道结果。 -
谢谢!在我的 json 中将
value更改为children解决了它! 1. 你能解释一下为什么一定要children吗? 2、那我的TreeStore中的root: 'value'有什么作用呢? 3.发布一个答案,我会接受它。