0

Note:- i want to call ClassA function "deleteEntryInternal" in another class B within "afterRequest function. how can i call this function in other class function.

My code is Below //here is my Class 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);
    }
}
5
  • You cannot call the function of a class, unless the function is static. You can only call the function on a class instance. For that, you would need an instance (var instanceA = Ext.create('A'); instanceA.deleteEntryInternal()) Commented Jan 23, 2017 at 12:07
  • Thanks for reply..!!! Commented Jan 23, 2017 at 12:57
  • How about mixins? Commented Jan 23, 2017 at 13:20
  • Than you, Yes its working, but when i call this function then i am not able to get data in "self._otherservicesGrid.getSelectionModel().getSelection();". row data is blank, so i am able to perform action, can you please guide me about this ? Commented Jan 23, 2017 at 14:01
  • fn: function (buttonId) { if (buttonId === "yes") { //Ext.deleteEntryInternal(false); var inst = Ext.create('WebCare.UI.OtherServicesEditor'); inst.deleteEntryInternal(false); } } Commented Jan 23, 2017 at 14:12

2 Answers 2

2

To call this method, you need to obtain instance of this class. And then you can call methods in that class.

1.You can get an instance of Ext.app.Controller by

var controllerInstance = appName.app.getController('appName.controller.controllerName');
controllerInstance.methodToCall();

where appName is name of your Extjs App.

2.If your class is a view which is already rendered , you can get its instance by -

var viewInstance = Ext.getCmp(viewId);
viewInstance.methodToCall();

where viewId is id of your view.

3. Static class - You can call methods of static class directly like if class MyStaticClass is static class , you can call its methods like -

MyStaticClass.methodToCall();
Sign up to request clarification or add additional context in comments.

Comments

-1

It is never a good idea to cross reference class methods on any way. Although Harshal's methods will work it is just very bad app design. If your class needs to react to an event what is happening in another class then why don't you just fire an event in class A and set up a listener in class B?

3 Comments

But i have to follow this design. so can you give me any idea for this ?
What sort of class triggering that event? I.e. what is the definition of the class containing the afterRequest function? Is it a controller, another view?
Yes, I agree. Ideally you should not need these type of method calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.