EXTJS4.0 tree.Panel 使用了model 取值 问题

Ext.regModel('EncyModel', { fields: ['ENCY_ID', 'UP_ENCY_ID', 'ENCY_NAME', 'ENCY_PAGE_ID', 'ENCY_SEQ'] });
//Nav_Title.activeTab(6);

//数据加载
var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: '/Ency/AjaxEncyGroup',
//url: '/Scripts/check-nodes2.json',
reader: {
type: 'json'
}
},
model: 'EncyModel',
nodeParam: 'ENCY_ID',
root: {
//ENCY_NAME: '百科',
//ENCY_ID: '-1'
text :'dd'//,
//id :'-1'
}
});

var tree = Ext.create('Ext.tree.Panel',
{
renderTo: "mainGroup",
store: store,
rootVisible: true,
useArrows: true,
title: "词条组管理",
//tbar: ['顶端工具'],
height: 400,
980,
frame: true,
bodyPadding: 5,
columns: [{
xtype: 'treecolumn',
//text: '百科',
dataIndex: 'ENCY_NAME',
text: '名称',
//dataIndex:'text',
150,
sortable: true//,
// listeners:
// {
// click: function (record,item, index,e) {

// alert(record.ENCY_NAME.text);
// }
//// ,
//// itemclick: function (tree, record, item, index, e, eOpts) {
//// alert(record.raw.text);

//// }
// }
//handler: onTreeLeaf//,
// viewConfig: {
// plugins: {
// ptype: 'treeviewdragdrop'
// }
// }
},
{
text: '编号',
dataIndex: 'ENCY_ID',
//items:[new Ext.menu.Item({text:'新建',handler:onMenuItem}),{text:'打开',handler:onMenuItem}],
//item:[{xtype:'combo'}],
//xtype:'textfield',
150,
sortable: true
}]
});

tree.on("itemclick", function (view, record, item, index, e) {

alert("点击的节点ID是:" + record.raw.ENCY_ID + ",文字是:" + record.raw.ENCY_NAME);

});

注意:Ext4.0 没有了 node 使用了 相同功能的 record,record中就像 model 一样取值,record.raw.ENCY_NAME 这是显示的名称 也是在 dataIndex:'ENCY_NAME'  是同一个值,一般都是用 text ,我在model 里没有定义 text 字段,但是一样使用 取值。感觉已经不是传统意义山个的 tree了。

tree.on("itemclick"   这一句 我用 click 去值 试了好久  都没有。 不知道 itemClick 于 click 有什么区别?

listeners:{

itemclick: function (view, record, item, index, e) {
alert('s')},
click: function (view, record, item, index, e) {
alert('s');

}
}

在panel 中配置 事件 itemclick 不能用 。click 可以用 但是(record.raw.ENCY_NAME)取不到值,是因为listens 配置到了 columns 内。

 外部配置 如下:

tree.on("itemclick", function (view, record, item, index, e) {
alert("点击的节点ID是:" + record.raw.ENCY_ID + ",文字是:" + record.raw.ENCY_NAME);

}); 

或者这样:

tree.addListener('itemclick',function (view, record, item, index, e){
alert(record.raw.text);
});

 能正常取值,itemClick 事件改为 click 不行。 

EXTJS 摸索中。。。

原文地址:https://www.cnblogs.com/90nice/p/3110319.html