2012-01-09 84 views
3

我有这个treepanel,我想调用this.getId()从“展开所有”按钮mainpaneltree的方法但我得到的是方法undefined.I试图把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方法,得到的任何子参考保持。