extJS - Call a function from another function within the same controller

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

--------------Solutions-------------

After onLocalOrganisationInfoAfterRender: function(component, eOpts) {

paste var that = this;

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

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

});

Category:javascript Time:2013-11-13 Views:0

Related post

  • Which is more preferable to use in Python: lambda functions or nested functions ('def')? 2008-09-25

    I mostly use lambda functions but sometimes use nested functions that seem to provide the same behavior. Here are some trivial examples where they functionally do the same thing if either were found within another function: Lambda function >>

  • Which languages support *recursive* function literals / anonymous functions? 2008-10-01

    It seems quite a few mainstream languages support function literals these days. They are also called anonymous functions, but I don't care if they have a name. The important thing is that a function literal is an expression which yields a function wh

  • what is the difference between re-entrant function and recursive function in C? 2008-11-04

    In C I know about the recursive function but I heard about the re-entrant function. What is that? And whats the difference between them? --------------Solutions------------- A function is re-entrant if it supports having multiple threads of execution

  • I want to know the difference between Low-level functions & Top-level functions 2009-03-11

    Charles Simonyi introduced the idea of "organizing really big software teams by creating one super duper uber programmer writing the top-level functions, while handing off the implementation of the lower-level functions to a team of grunt junior-prog

  • Passing a function to another function in C. What am I doing wrong? 2009-03-18

    Got some C code I'm working on, and it looks like it should work. When I try to link the object files, I get an error saying "undefined reference to outputBus" and so on for each of them in the getLine function in main. I've tried it with and without

  • Member function vs. nonmember function? 2009-04-03

    What is your rule for which functions that operate on a class should be member functions vs. nonmember functions? For example, I have a class which represents a maze using a matrix of bools. I am making a function called isConnected which verifies th

  • PHP call a function from a function 2009-04-26

    What's the PHP code that would do one thing first and then take that and do a second. 1st: I want $_GET a variable and then run a query on it and return variables. AND THEN 2nd: Use those "other" variables in a query. I'm thinking I want to do this w

  • calling a javascript function (in original function) from called function? 2009-05-13

    Is there anyway to calling a function from another function .. little hard to explain. heres in example. One function loads html page and when ready it calls the original function. I think i need to pass in a reference but unsure how to do this... if

  • in flex, get function name from Function object 2009-08-04

    Given a Function object, can you get its name as a String? See example: function doThingWithCallback(callback:Function):void { trace("i'm going to run " + callback); // outputs "i'm going to run function Function() { }" } function foo():void { ... }

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.350 (s). 13 q(s)