2011-05-31 83 views
1

我還有另一個問題與extjs。當我構建treeview時,我無法獲得與樹節點一起工作的範圍。根節點的範圍是我的js對象,而不是作爲範圍返回窗口的treenode。Extjs treePanel節點範圍問題

任何想法爲什麼?

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

回答

2

當使用TreePanel的我通常把click事件上TreePanel中,而不是在每一個節點。如果您不需要click事件以不同的方式爲每個節點進行處理,把click事件TreePanel中這樣的:

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

現在click事件的範圍與創建樹型面板時相同,並且您仍然可以訪問用戶正在點擊的節點。

+0

感謝您的回答。 – 2011-05-31 14:06:46