Extjs callback function for controller

I have the following base class that processes the entire request

makeRequest: function(mydata) {
    Ext.Ajax.request({
        url: './handler.php',
        method: 'GET',
        scope: this,
        params: {
            data: mydata
        },
        callback: this.myResponse,
        success: function(xhr, params) {
            console.log('Success');
        },
        failfure: function(xhr, params) {
            console.log('Failure');
        }
    });
}

In my controller I have

.............
requires: [
  'Test.libs.Request'
],

............
onItemClick: function() {
  var objCallback = Ext.create('Test.libs.Request', {
    scope: this
  });
  objCallback.makeRequest(1);
},

myResponse: function(options, success, response) {
    console.log(response);
}

After successful execution, how can I get myResponse controller as a callback?

+4
source share
1 answer

You need to go through fn and area, something like:

Ext.create('Test.libs.Request', {
    callback: this.myResponse
    scope: this
}); 

// You need to get a reference to those passed params inside your request method.
Ext.Ajax.request({
    url: './handler.php',
    method: 'GET',
    scope: passedScope,
    params: {
        data: mydata
    },
    callback: passedCallback
});
+2
source

Source: https://habr.com/ru/post/1527780/


All Articles