定义一个model,也可以不定义直接写在TreeStore里
Ext.define('treeModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'text', type: 'string'}, //这个不写就没了
{name: 'url', type: 'string'}
]
});
TreeStore
var store = Ext.create('Ext.data.TreeStore', {
nodeParam: 'id', //默认的是把id作为node传到后台
//model: 'treeModel',
//autoLoad: false,
// 属性域
fields: [
{name: 'text', type: 'string'}, //这个不写就没了?
{name: 'url', type: 'string'}
],
proxy: {
type: 'ajax',
url: 'resource/getListByPU.json',
reader: {
type: 'json',
root: 'extTreeVoList' //josn中的根节点
}
},
root: {
text: '根节点',
id: 0,
expanded: true
}
// ,
// sorters: [{
// property: 'text',
// direction: 'ASC'
// }]
});
treePanel
var tree = Ext.create('Ext.tree.Panel', {
//id: extTreeVo.id, //id值可能被占用了
title: 'text',
store: store,
rootVisible:false,
useArrows: false,
listeners : {
'itemclick' : function(view,record){
if(record.data.leaf){
alert(record.data.id+record.data.url);
alert(record.raw.url); //不扩展也能从raw取
}else{
// if(record.data.expanded){
// view.collapse(record);
// }else{
// view.expand(record);
// }
}
}
}
});
data里貌似有个href可以利用,好像url就不用扩展了
用火狐调试监控的record.data的所有属性
data
Object { id=20, text="组织机构管理", parentId=10, 更多...}
id
20
text
"组织机构管理"
parentId
10
index
0
depth
1
expanded
null
expandable
true
checked
null
leaf
true
cls
"file"
iconCls
""
icon
""
root
false
isLast
false
isFirst
true
allowDrop
true
allowDrag
true
loaded
false
loading
false
href
""
hrefTarget
""
qtip
""
qtitle
""
qshowDelay
0
children
null