gpt4 book ai didi

javascript - extjs 4 中的范围问题

转载 作者:行者123 更新时间:2023-11-29 10:22:29 25 4
gpt4 key购买 nike

我有这个树面板,我想从“全部展开”按钮内部调用 mainpaneltree 的 this.getId() 方法但我得到的只是未定义的方法。我试图将 scope :this在配置对象中,但没有成功。

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

所以我的问题是如何在当前组件的嵌套方法或配置对象中获取对当前组件的引用并调用其方法

最佳答案

处理程序有传入的参数,其中 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);
}
});

关于javascript - extjs 4 中的范围问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8792138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com