7

我想要做的是在不同的树 LEAF click 上获得不同的反应!

var myTree = Ext.create('Ext.tree.Panel',
    store: store,
    rootVisible: false,   
    border: false,
    listeners: {
        itemclick: function(index) {            
            var record = store.getAt(index);
            alert(record);          
        }
    }
});

我尝试使用索引来获取叶子的索引,什么都没有。我可以在节点点击时获得反应,但如何在每片叶子上获得特定反应?我也试过给叶子ID,没有运气???

也许是一个简单的例子

itemclick: function(Ext.view.View this, Ext.data.Model record, HTMLElement item, Number index, Ext.EventObject e) {  

}

请帮忙!!

4

3 回答 3

10

事件监听器的itemclick函数参数“index”不指向你的树节点的索引。就像您在问题末尾提到的那样,itemclick事件的语法是:

function(Ext.view.View this, Ext.data.Model record, HTMLElement item, Number index, Ext.EventObject e) {

}

这是一个例子:

itemclick : function(view,rec,item,index,eventObj) {

    // You can access your node information using the record object
    // For example: record.get('id') or record.get('some-param')
    if(r.get('id')=='SP') {
        // I do my necessary logic here.. may be open a perticular window, grid etc..
    }

    if(r.get('id')=='CO') {
        // I do my necessary logic here.. may be open a perticular window, grid etc..
    }           
}

这是我的树节点数据的示例:

{ text: 'SP Reports', id: 'SP', leaf: true},
{ text: 'CO Reports', id: 'CO', leaf: true},
于 2011-05-23T09:24:34.347 回答
6

Itemclick 处理程序已经为您提供了所需的一切:

itemclick(view, record, item, index, e ) {
    var id = record.get('id');
    // do something depending on the record data.
    // console.log(record);
}
于 2011-05-23T09:23:58.827 回答
3

I was trying to do a generic treepanel's item click handler and to be able to get a custom field I added to the node object. This helped me out. I dunno if this is the standard and compatible ExtJs 4 way:

            (Some Panels Here),
            items: [{
                xtype: 'treepanel',
                listeners: {
                    itemclick: {

                        fn: function (view, record, item, index, e) {

                            console.log(record.raw.userData);
                        }
            (removed...)
于 2011-09-02T11:01:41.813 回答