2

Can you tell me why this gets me

Cannot call substring of undefined. Cannot call method getModel of undefined.

Ext.require(                   
    ['MyApp.controller.Country', 'MyApp.controller.CountryProperties'],     // this auto-loads all dependencies 
    function(){ 
            // ... as soon as this class 
            //    and all its dependencies have loaded...
        var controller = Ext.create('MyApp.controller.Country');  // create an instance
        var controller2 = Ext.create('MyApp.controller.CountryPropeties');  // create an instance
        controller.init();                  // launch init() method
        controller2.init();
    }
);

But when I add those controllers, views, stores and models manually in app.js into controllers: [], views: [] etc. it works.

Btw. I have inside controller -> stores:[], views: [] so when I load only a controller, it should load any dependencies for controller.

Why I get that error?

Thank you. :)

  • 1
    Since the problem seems to be inside the `init()` functions, maybe it would be clearer if you provide some more code. Because your controllers are created but something else is the problem. – Kosta Dec 06 '12 at 09:05

3 Answers3

3

Just in addition to @arshabh answer which is perfectly right.

If you call (rev 1. - fixed typo)

this.application.getController('Country');
this.application.getController('CountryPropeties');

from your controller you get exactly the same result as you do it, just a little simpler. Note that the application getter automatically load missing classes and for the controller or store initialize/register them.

sra
  • 23,820
  • 7
  • 55
  • 89
  • Oh yeah. If they doesn't exist, Ext-JS would create them. Is that right? –  Dec 06 '12 at 11:55
  • 2
    @user1509885 LOL. Even if you think that sounds funny the answer is yes. My lines are the same as your lines. The controller will first lookup if the are already instantiated and if not try to instantiate them and if they don't exist require them. After that instantiate them, init them, register them and then hand the instance back to you. – sra Dec 06 '12 at 12:03
  • Ok, I'll try. Thank you very much. You've helped me a lot of times. :D –  Dec 06 '12 at 16:16
  • @user1509885 Only note that I referencing to 4.1.3 and I am not quite sure since which version the init() method is called by the getController() method. I just know that in 4.0.7 I had to do it by myself. Anyway, the rest work as described. – sra Dec 06 '12 at 16:46
  • I'm getting this: Uncaught TypeError: Cannot call method 'getModel' of undefined –  Dec 06 '12 at 16:47
  • 1
    @user1509885 note that the scope need to be the correspondenting application controller instance. Called from a controller this would be this.application – sra Dec 06 '12 at 17:14
0

your code is perfect, but you are forgetting the scope(this)

please make a small change in the code as follows

    Ext.require(                   
['MyApp.controller.Country', 'MyApp.controller.CountryProperties'],     // this auto-loads all dependencies 
function(){ 
        // ... as soon as this class 
        //    and all its dependencies have loaded...
    var controller = Ext.create('MyApp.controller.Country');  // create an instance
    var controller2 = Ext.create('MyApp.controller.CountryPropeties');  // create an instance
    controller.init();                  // launch init() method
    controller2.init();
},this
   );
arshabh
  • 166
  • 3
  • 8
0

What worked for me was

this.application.getController('Country').doInit(this);

Cheers
Edgar

Edgar Villegas Alvarado
  • 18,204
  • 2
  • 42
  • 61