1
我想將JSON文件加載到TreeStore中以在TreePanel中使用。我可以加載商店的值,並顯示如果我硬編碼的樹,但是當我嘗試從JSON文件加載它,它不會顯示樹中的任何東西。這裏是我的代碼:如何將JSON加載到TreeStore?
JSON文件:exampleDoc.json
{
"success": true,
"Root": [
{
"name": "Bookmark 1",
"leaf": true,
"element": "1"
},{
"name":"Bookmark 2",
"leaf": true,
"element": "2"
},{
"name":"Bookmark 3",
"leaf": true,
"element": "3"
}
]
}
這裏是我的模型
Ext.define('bkmark', {
model : 'Ext.data.Model',
fields : ['name', 'element']
});
這裏是我的樹商店
var store = Ext.create('Ext.data.TreeStore', {
model: 'bkmark',
proxy: {
type: 'ajax',
url : 'exampleDoc.json',
reader: {
type: 'json'
}
}
});
這裏是我的樹面板
var treePanel = Ext.create('Ext.tree.Panel', {
title: 'Bookmarking',
width: 225,
height: 150,
store: store,
rootVisible: false,
region: 'west',
collapsible: true,
});
在此先感謝!