1

我对extjs还有另一个问题。当我构建树视图时,我无法获得使用树节点的范围。根节点的范围是我的 js 对象,而不是返回窗口作为范围的 treenode。

知道为什么吗?

树形面板定义:

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); 
                }
            }
        }
    }
]
4

1 回答 1

2

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

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

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

于 2011-05-31T13:41:09.880 回答