ExtJS树面板不显示子级
我调用store.load,但treepanel只显示第一级模型ProcessVedDoc。如果我向load方法添加回调,我会在记录中看到空的childNodes。虽然数据中有子对象,但对象未映射到模型VedDoc。有什么不对劲吗? 模型ExtJS树面板不显示子级,extjs,extjs4,extjs4.2,Extjs,Extjs4,Extjs4.2,我调用store.load,但treepanel只显示第一级模型ProcessVedDoc。如果我向load方法添加回调,我会在记录中看到空的childNodes。虽然数据中有子对象,但对象未映射到模型VedDoc。有什么不对劲吗? 模型 Ext.define('Proj.model.ProcessVedDoc', { extend: 'Ext.data.Model', fields: [ {name: "text", mapping: 'name'}, {name: "exp
Ext.define('Proj.model.ProcessVedDoc', {
extend: 'Ext.data.Model',
fields: [
{name: "text", mapping: 'name'},
{name: "expanded", type: "boolean", defaultValue: true},
{name: "loaded", type: "boolean", defaultValue: true}
}],
requires : ['Proj.model.VedDoc'],
hasMany: [{
model: 'Proj.model.VedDoc',
associationKey : 'children',
name: 'children'
}]});
Ext.define('Proj.model.VedDoc', {
extend: 'Ext.data.Model',
fields: ['id',
{name: 'text', mapping: 'name'},
{name: 'leaf', type: 'boolean', defaultValue: true, persist: false}],
idProperty: 'id'});
贮藏
看法
Json
您需要从扩展模型以在存储中构建树。尝试以该格式做出响应,因为root用户了解子对象 JSON格式 ExtJs树面板和存储代码 我已经创建了一个演示。你在这里检查 注意*您可以在前端设置treedata格式,并使用setRoot{your root object}在存储中加载数据。欲知详情
我想你错过了leaf酒店。谢谢你的回答。此字段位于ExtJs VedDoc模型中。我换了json。添加了“叶”并重命名为“名称”->“文本”。问题依然存在。{text:Doc1,id:7813eb3c-57f9-4f39-aefc-af4860441189,leaf:true}非常感谢。这是工作。问题出在错误的一级孩子的名字上。
Ext.define('Proj.store.VedDocsTreeStore', {
extend: 'Ext.data.TreeStore',
model: 'Proj.model.ProcessVedDoc',
autoLoad: false,
autoSync: false,
root: {
expanded: true
},
proxy: {
type: 'ajax',
url: 'portfolios/veddocs',
getParams: Ext.emptyFn,
timeout: 300000,
reader: {type: 'json', root: 'docs'}
}});
{
xtype: 'treepanel',
title: 'Documents',
name: 'vedDocs',
margin: '15 0 0 0',
width: 650,
height: 350,
rootVisible: false,
store: vdocs
}
{
"docs": [{
"name": "15a1dc1515aa151eea556",
"children": [
{"name": "Doc1", "id": "bf4e2776-1089-445f-98dd-e5e8fe5c798f"},
{"name": "Doc2", "id": "1312bba6-9d05-4aa5-b069-b2958043c2a5"},
{"name": "Doc3, "id": "49a045cf-b5cf-4478-b886-f078e6a48753"}]
},
{
"name": "15a1dc18515bb515aa151556",
"children": [
{"name": "Doc1", "id": "3cef1250-fd35-4ff6-bbbf-33e4c59d4767"},
{"name": "Doc2", "id": "a43ffa24-ed25-4fc7-80a5-f4b1a78b666e"}]
}],
"success": true}
{
"success": true,
"children": [{
"text": "15a1dc1515aa151eea556",
"expanded": true,
"children": [{
"text": "Doc1",
"leaf": true,
"id": "bf4e2776-1089-445f-98dd-e5e8fe5c798f"
}, {
"text": "Doc2",
"leaf": true,
"id": "1312bba6-9d05-4aa5-b069-b2958043c2a5"
}, {
"text": "Doc3",
"leaf": true,
"id": "49a045cf-b5cf-4478-b886-f078e6a48753"
}]
}, {
"text": "15a1dc18515bb515aa151556",
"expanded": true,
"children": [{
"text": "Doc1",
"leaf": true,
"id": "3cef1250-fd35-4ff6-bbbf-33e4c59d4767"
}, {
"text": "Doc2",
"leaf": true,
"id": "a43ffa24-ed25-4fc7-80a5-f4b1a78b666e"
}]
}]
}
var store = Ext.create('Ext.data.TreeStore', {
autoLoad: true,
autoSync: false,
root: {
expanded: true
},
proxy: {
type: 'ajax',
url: 'veddocs.json',
timeout: 300000,
reader: {
type: 'json',
root: 'children'
}
}
});
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
renderTo: Ext.getBody()
});