1

Super-stupid question, but I can't make it work, how do we call a function from another function within the same Controller? I use sencha architect.

Here is my controller where I a have a listener and a function, I want to call generateField function from the listener

Ext.define('Medlemssystem.controller.MemberOrganisationController', {
    extend: 'Ext.app.Controller',

    views: [
        'LocalOrgPanel'
    ],

    onLocalOrganisationInfoAfterRender: function(component, eOpts) {

        main_id = component.up('#memberTab').main_id;

        component.removeAll();

        Ext.Ajax.request({
            url: 'OrganizationCustomFieldServlet',
            method: 'GET',
            dataType: 'json',
            params: {
                "operation" : "get",
                "org_id" : main_id 
            },
            success: function(response) {
                var result = Ext.decode(response.responseText);
                result.forEach(function(n) {
                    component.add(generateField(n.customField.name));
                });
            },
            failure: function() {
                console.log('woops');
            }
        });
    },

    generateField: function(name, type, id, required, description) {
        var field = Ext.create("Ext.form.field.Text", {fieldLabel:name});

        return field;
    },

    init: function(application) {
        this.control({
            "LocalOrgPanel": {
                afterrender: this.onLocalOrganisationInfoAfterRender
            }
        });
    }

});

when I call component.add(generateField(n.customField.name)); I get "function not found" error

2 Answers 2

3

After onLocalOrganisationInfoAfterRender: function(component, eOpts) {

paste var that = this;

And then component.add(that.generateField(n.customField.name));

Sign up to request clarification or add additional context in comments.

Comments

2

An alternative way is to set scope for the ajax request call back.

Like this

Ext.Ajax.request({
        url: 'OrganizationCustomFieldServlet',
        method: 'GET',
        dataType: 'json',
        params: {
            "operation" : "get",
            "org_id" : main_id 
        },
        success: function(response) {
           console.log(this); //<-- scope here is Window by default, unless scope is set below
        },
        failure: function() {
            console.log('woops');
        },
        scope :this //<--   Sets the controller as the scope for the success call back

    });

1 Comment

Thank you for the explanation. This is also a correct answer, but I will accept sine's answer since he posted it earlier :-)

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.