1

extjsにはさらに別の問題があります。ツリービューを作成すると、スコープをツリーノードで機能させることができません。ルートノードのスコープは、ウィンドウをスコープとして返​​すtreenodeとは対照的に、私のjsオブジェクトです。

なぜですか?

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

1 に答える 1

2

を使用する場合、通常、各ノードではなくツリーパネルTreePanelにクリックイベントを配置します。クリック イベントをノードごとに異なる方法で処理する必要がない場合は、次のようにクリック イベントツリーパネルに配置します。

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 に答える