Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在extjs4中的不同类B函数中从类A调用函数_Extjs - Fatal编程技术网

如何在extjs4中的不同类B函数中从类A调用函数

如何在extjs4中的不同类B函数中从类A调用函数,extjs,Extjs,注意:-我想在“afterRequest”函数中的另一个类B中调用类A函数“deleteEntryInternal”。如何在其他类函数中调用此函数 我的代码在下面 //这是我的A班 Ext.define('WebCare.UI.OtherServicesEditor', { extend: 'Ext.WebCare.UI.BaseEditor', _otherservicesGrid: null, alias: 'widget.otherserviceseditor', title: 'Othe

注意:-我想在“afterRequest”函数中的另一个类B中调用类A函数“deleteEntryInternal”。如何在其他类函数中调用此函数

我的代码在下面 //这是我的A班

Ext.define('WebCare.UI.OtherServicesEditor', {
extend: 'Ext.WebCare.UI.BaseEditor',
_otherservicesGrid: null,
alias: 'widget.otherserviceseditor',
title: 'Other Services',
defaultType: 'textfield',
id: 'otherservicesEditor',

deleteEntryInternal: function (isDelete) {
    this.disableForm();
    var self = this;
    var selection =     self._otherservicesGrid.getSelectionModel().getSelection();
    if (selection.length > 0) {
        if (isDelete) {
            selection[0].data.IsDelete = true;
        }
        this.deleteServerRecord(selection[0].data, function () { });

        vent.trigger(otherServicesStore.storeId, selection[0].data);
    }
}

若要调用此方法,需要获取该类的实例,然后才能调用该类中的方法

1.您可以通过

var controllerInstance = appName.app.getController('appName.controller.controllerName');
controllerInstance.methodToCall();
其中appName是您的Extjs应用程序的名称

2.如果您的类是已渲染的视图,则可以通过-

var viewInstance = Ext.getCmp(viewId);
viewInstance.methodToCall();
其中视图id是视图的id

3.静态类- 您可以直接调用静态类的方法,就像类MyStaticClass是静态类一样,您可以像-

MyStaticClass.methodToCall();

以任何方式交叉引用类方法都不是一个好主意。虽然Harshal的方法会起作用,但这只是一个非常糟糕的应用程序设计。如果您的类需要对另一个类中发生的事件做出反应,那么为什么不在类a中触发一个事件并在类B中设置一个侦听器?

您不能调用类的函数,除非s该函数是静态的。您只能在类实例上调用该函数。为此,您需要一个实例(
var instanceA=Ext.create('a');instanceA.deleteEntryInternal()
)谢谢您的回复!!!怎么样?与您相比,是的,它工作正常,但当我调用此函数时,我无法获取数据”self._otherservicesGrid.getSelectionModel().getSelection();“.row数据是空的,所以我可以执行操作,您能指导我吗?fn:function(buttonId){if(buttonId==“yes”){//Ext.deleteEntryInternal(false);var inst=Ext.create('WebCare.UI.OtherServicesEditor'));inst.deleteEntryInternal(false);}但是我必须遵循这个设计。那么你能给我一些想法吗?什么样的类触发了那个事件?例如,包含afterRequest函数的类的定义是什么?它是控制器还是另一个视图?是的,我同意。理想情况下,你不应该需要这些类型的方法调用。