Extjs 如何将一个 JSON 文件夹结构加载到树中?
Extjs How to load a JSON folder structure into a tree?
我正在尝试用 JSON 数据创建一个 Extjs 树。我要加载到树中的数据包含一个文件夹结构。但是当我尝试将数据加载到树中时,它没有显示任何内容。
我检查了 json 代码 here (JSONLint) 是否有错误,但一切正常。这会说问题可能出在 extjs 部分。
我不知道如何让它工作。
我创建了一个 JSON-对象,如下所示:
{
"folders": [
{
"name": "Function",
"id": "workspace://SpacesStore/000-000-000",
"folders": [
{
"name": "Evaluation reports",
"id": "workspace://SpacesStore/00-00-4949-9caf-6655fg"
},
{
"name": "Function Reports",
"id": "workspace://SpacesStore/554gg-563-sd555-872e-0098hhjf"
},
{
"name": "Training(POP)",
"id": "workspace://SpacesStore/4334g-67hj-4357-ba96-4343fhj343"
}
]
},
{
"name": "Application data",
"id": "workspace://SpacesStore/3434gg-a761-48a2-83fa-3434f454hu",
"folders": [
{
"name": "Application letters",
"id": "workspace://SpacesStore/23232ff-c95f-4999-sdsd556-00886ggh7765"
}
]
}
]
}
这是我要加载 JSON 数据的 Extjs 部分:
initComponent: function() {
// declare a new store and load tree data
this.store = new Ext.data.TreeStore({
// set params
proxy: {
type: 'ajax',
reader: 'json',
url: 'http://localhost:8080/testApp/rest/folder/1'
}
});
this.items = [{
flex: 1
}];
this.callParent();
}
你没有告诉 reader 要读什么 属性:
reader: {
type: 'json',
rootProperty: 'folders'
}
我正在尝试用 JSON 数据创建一个 Extjs 树。我要加载到树中的数据包含一个文件夹结构。但是当我尝试将数据加载到树中时,它没有显示任何内容。
我检查了 json 代码 here (JSONLint) 是否有错误,但一切正常。这会说问题可能出在 extjs 部分。
我不知道如何让它工作。
我创建了一个 JSON-对象,如下所示:
{
"folders": [
{
"name": "Function",
"id": "workspace://SpacesStore/000-000-000",
"folders": [
{
"name": "Evaluation reports",
"id": "workspace://SpacesStore/00-00-4949-9caf-6655fg"
},
{
"name": "Function Reports",
"id": "workspace://SpacesStore/554gg-563-sd555-872e-0098hhjf"
},
{
"name": "Training(POP)",
"id": "workspace://SpacesStore/4334g-67hj-4357-ba96-4343fhj343"
}
]
},
{
"name": "Application data",
"id": "workspace://SpacesStore/3434gg-a761-48a2-83fa-3434f454hu",
"folders": [
{
"name": "Application letters",
"id": "workspace://SpacesStore/23232ff-c95f-4999-sdsd556-00886ggh7765"
}
]
}
]
}
这是我要加载 JSON 数据的 Extjs 部分:
initComponent: function() {
// declare a new store and load tree data
this.store = new Ext.data.TreeStore({
// set params
proxy: {
type: 'ajax',
reader: 'json',
url: 'http://localhost:8080/testApp/rest/folder/1'
}
});
this.items = [{
flex: 1
}];
this.callParent();
}
你没有告诉 reader 要读什么 属性:
reader: {
type: 'json',
rootProperty: 'folders'
}