我的代码看起来像这样,但商店/树中没有数据。
JSON 存储是否有效?我需要root
在 JSON 之上吗?
树面板中必须定义哪些列?
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
}
]
} );