gpt4 book ai didi

javascript - Extjs 树面板未加载 json 数据

转载 作者:行者123 更新时间:2023-11-30 17:44:33 25 4
gpt4 key购买 nike

您好,我正在尝试通过 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 没有显示错误,
知道我做错了什么吗?

提前致谢

最佳答案

在您的商店中,您将根 ID 称为 src,但您的 json 没有 src 的 ID。

在示例链接 JSON 如下所示,id 被称为“src/fx”,其中 src 是根

{text:fx, id:src/fx, cls:folder, qtip:Type: Folder<br />Last Modified: Jul 9, 2013, 3:24 am}

要让你的东西正常工作,只需从根目录中删除 id

var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'treeJson.json'
},
root: {
expanded: true
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});

关于javascript - Extjs 树面板未加载 json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20373824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com