2012-01-09 13 views
3

私はこのtreepanelを持っています。私は "expand all"ボタンの中からthis.getId() mainpaneltreeのメソッドを呼び出したいと思っています。しかし、すべて私が得る方法は定義されていません。scope:thisを設定オブジェクトに入れようとしました。 extjsのスコープの問題4

Ext.define('MA.view.patient.Tree', { 
extend : 'Ext.tree.Panel', 
alias : 'widget.EditPatientTree', 
title : 'Simple Tree', 
width : 150, 
store:'Tree', 
dockedItems : [ { 
    xtype : 'toolbar', 
    items : [ { 
     text : 'Expand All', 
     scope: this, 
     handler : function() { 
    //this.expandAll gives "Uncaught TypeError: Object [object DOMWindow] has no method 'getId'" 
      this.expandAll(); 
    //the same error for this.getId(); 
      this.getId(); 
     } 
    } ] 
} ], 
rootVisible : false, 
initComponent : function() { 
    this.callParent(arguments); 
} 
}); 

は、だから私の質問は、現在のコンポーネントへの参照を取得し、あなたが

答えて

3

ハンドラは、1の中に渡される引数を持ち、現在のコンポーネントのネストされた方法や設定オブジェクトの内側にある一方で、そのメソッドを呼び出す方法ですそれらは通常はボタンです。ボタンからコンテナを得ることができます。

Ext.define('MA.view.patient.Tree', { 
extend : 'Ext.tree.Panel', 
alias : 'widget.EditPatientTree', 
title : 'Simple Tree', 
width : 150, 
store:'Tree', 
dockedItems : [ { 
    xtype : 'toolbar', 
    items : [ { 
     text : 'Expand All', 
     scope: this, 
     handler : function(button, event) { 
      var toolbar = button.up('toolbar'), treepanel = toolbar.up('treepanel'); 
      treepanel.expandAll(); 
      treepanel.getId(); 
     } 
    } ] 
} ], 
rootVisible : false, 
initComponent : function() { 
    this.callParent(arguments); 
} 
}); 
1

あなたが親または子なコンポーネントの参照を取得のためのupdownのような方法を利用することができます。あなたのケースでは、あなたがして、ツリーパネルの参照を取得できます。同様に

myTree = this.up('treepanel'); 

、あなたはどの子参照のホールドを取得するには、downメソッドを使用することができます。