【发布时间】:2025-12-08 01:15:02
【问题描述】:
您好,我正在尝试通过 json 和
为树形面板加载数据
我指的是this link。树面板正常显示,但没有数据。
这是我的代码
编辑按照 Objectone 的建议更新了代码
Ext.require([
'Ext.tree.*',
'Ext.data.*',
'Ext.tip.*'
]);
Ext.onReady(function() {
var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'treeJson.json'
},
root: {
expanded: true
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});
var tree = Ext.create('Ext.tree.Panel', {
store: store,
renderTo: 'tree-div',
height: 300,
width: 250,
title: 'Files',
useArrows: true,
dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'Expand All',
handler: function(){
tree.expandAll();
}
}, {
text: 'Collapse All',
handler: function(){
tree.collapseAll();
}
}]
}]
});
console.log(store.getRootNode());
});
这里是 json
[
{
"text": "To Do",
"cls": "folder",
"expanded": true,
"children": [
{
"text": "Go jogging",
"leaf": true
},
{
"text": "Take a nap",
"leaf": true
},
{
"text": "Climb Everest",
"leaf": true
}
]
}
]
Firebug 没有显示错误,
知道我做错了什么吗?
提前致谢
【问题讨论】:
-
将 JSON 的 id 设为“src”
-
Kishan,我试图为 json 提供 id 但它不起作用,现在我从 root 中删除了 id 但它只显示 root。
标签: javascript json extjs extjs4