Extjs treePanel节点范围问题

时间:2011-05-31 13:22:00

标签: extjs treeview scope treenode

我还有另一个extj问题。当我构建treeview时,我无法使用树节点来处理范围。根节点的范围是我的js对象,而treenode则返回窗口作为范围。

知道为什么吗?

TreePanel定义:

this.treeForParamPanel= new Ext.tree.TreePanel(
{
    layout: 'fit',
    frame:true,
    iconCls:'search',

    animCollapse:false,
    collapsedIconCls: 'search',
    titleCollapse :true,
    collapsible: true,
    split:true,
    collapsed: false,
    animate: false,
    lines: true,
    id:'treeParamPanel'+this.id,
    region:region,
    title: 'aaa',
    anchor:'100%',
    //rootVisible:false,
    width: 200,
    height:300,
    border:false,
    autoScroll:true,

    loader: new Ext.tree.TreeLoader({
        scope:this,
        dataUrl:'index.php?act=index.php'
    })
});
this.rootTreeForParamPanel = new Ext.tree.AsyncTreeNode({
    text: 'aaa',
    draggable:false,
    id:'source',
    scope:this,
    listeners: {
        click: { 
            scope:this,
            fn:function(ev) { 
                alert(this); 
            }
        }
    }
});
this.treeForParamPanel.setRootNode(this.rootTreeForParamPanel);

项目定义:

[
    {
        "text": "testyybvnvbnvb",
        "id": "16",
        "leaf": true,
        "draggable": "false",
        "qtip": "aaa",
        listeners: {
            click: { 
                scope: this,
                fn:function(ev) { 
                    alert(this); 
                }
            }
        }
    }
]

1 个答案:

答案 0 :(得分:2)

使用TreePanel时,我通常会将click事件放在 treepanel 上而不是每个节点上。如果您不需要为每个节点以不同方式处理单击事件,请将单击事件放在 treepanel 上,如下所示:

this.treeForParamPanel = new Ext.tree.TreePanel(
{
    ... your parameters...
    listeners:
    {
        click: function(node, event) {
            alert('You have clicked on node ' + node.id);
        },
        scope: this
    }
});

现在单击事件的范围与创建 treepanel 时的范围相同,您仍然可以访问用户单击的节点。