我有一个基于以下代码的树形网格:
Ext.application({
name : 'Fiddle',
launch : function() {
var treeData = [{
mtype: 'InsDataModel',
recordid: '1',
companyname: 'Company 1',
children:[{
mtype: 'PlnDataModel',
recordid: '1A',
planname: 'Plan 1A'
},{
mtype: 'PlnDataModel',
recordid: '1B',
planname: 'Plan 1B'
}]
},{
mtype: 'InsDataModel',
recordid: '2',
companyname: 'Company 2',
children: []
},{
mtype: 'InsDataModel',
recordid: '3',
companyname: 'Company 3',
children:[{
mtype: 'PlnDataModel',
recordid: '3A',
planname: 'Plan 3A'
},{
mtype: 'PlnDataModel',
recordid: '3B',
planname: 'Plan 3B'
},{
mtype: 'PlnDataModel',
recordid: '3C',
planname: 'Plan 3C'
},{
mtype: 'PlnDataModel',
recordid: '3D',
planname: 'Plan 3D'
},{
mtype: 'PlnDataModel',
recordid: '3E',
planname: 'Plan 3E'
}]
}];
Ext.define('InsDataModel',{
extend: 'Ext.data.TreeModel',
childType: 'PlnDataModel',
fields:[
{name: 'recordid'},
{name: 'text', mapping:'companyname'}
]
});
Ext.define('PlnDataModel',{
extend: 'Ext.data.TreeModel',
fields:[
{name: 'recordid'},
{name: 'text', mapping:'planname'}
]
});
Ext.define('InsDataStore',{
extend: 'Ext.data.TreeStore',
model: 'InsDataModel',
proxy:{
reader:{typeProperty: 'mtype'}
},
data:treeData,
});
Ext.define('InsDataGrid',{
extend: 'Ext.tree.Panel',
store: {
model: 'InsDataModel',
proxy:{
type: 'memory',
reader:{typeProperty: 'mtype'}
},
data:treeData
},
title: 'My tree Demo',
renderTo: Ext.getBody(),
width: 400,
height: 600,
useArrows: true,
columns:[{
text: 'Network',
dataIndex: 'text',
flex: 1
}]
});
var newTree = Ext.create('InsDataGrid').show();
}
});
其中也位于:https://fiddle.sencha.com/#fiddle/136t
我遇到的问题是子节点在展开父节点时不会显示文本。有人可以看看代码,让我知道我做错了什么。谢谢。
答案 0 :(得分:1)
mapping
作为字符串要求读者读取远程响应以构建执行映射的函数。另外,您应该从childType
型号中移除InsDataModel
:https://fiddle.sencha.com/#fiddle/136u