Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Why does this.getApplication().getController('MainController').testFunction(); fail

  1. #1
    Sencha User
    Join Date
    Dec 2011
    Location
    White Rock, BC Canada
    Posts
    167
    Answers
    12

    Default Answered: Why does this.getApplication().getController('MainController').testFunction(); fail

    with error:
    Uncaught TypeError: Object [object Object] has no method 'getApplication'

  2. There is not 'getApplication' method in your views. You must get a reference to the global application reference using:

    Code:
    MyAppName.app.getController(...);
    Where 'MyAppName' is the name you define when you create your app using Ext.application.

  3. #2
    Sencha User
    Join Date
    Dec 2011
    Location
    White Rock, BC Canada
    Posts
    167
    Answers
    12

    Default

    To clarify: This is when called from a View

  4. #3
    Sencha User rdougan's Avatar
    Join Date
    Oct 2008
    Posts
    1,159
    Answers
    93

    Default

    There is not 'getApplication' method in your views. You must get a reference to the global application reference using:

    Code:
    MyAppName.app.getController(...);
    Where 'MyAppName' is the name you define when you create your app using Ext.application.
    Sencha Inc.
    Robert Dougan - @rdougan
    Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.

  5. #4
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Answers
    28

    Default

    Just wanted to add here that calling a method on a controller from within a View is very bad practice. Instead you should fire an event in your View, and have a Controller listen for that event using the 'control' configuration/syntax.

  6. #5
    Sencha User
    Join Date
    Dec 2011
    Location
    White Rock, BC Canada
    Posts
    167
    Answers
    12

    Default

    Thanks Tommy, I wanted to do that, but the Designer barfed with a message, something about not putting an id on a top-level object or events will not fire.

    What I need to do is call code in the controller when the activate event is fired on the view.

    Any better ideas as to how to do that?

  7. #6
    Sencha User
    Join Date
    Dec 2011
    Location
    White Rock, BC Canada
    Posts
    167
    Answers
    12

    Default

    @rdougan... thanks that worked perfectly. Another related question... how can I get a store reference? I tried:

    Code:
    var store = App.app.getStore('Settings');
    and I get the message:

    Uncaught TypeError: Object [object Object] has no method 'getStore'

  8. #7
    Sencha User
    Join Date
    Sep 2011
    Posts
    46
    Answers
    1

    Default

    Use Ext.getStore instead

  9. #8
    Sencha Premium Member
    Join Date
    Apr 2012
    Location
    Lausanne, Switzerland
    Posts
    196
    Answers
    1

    Default

    Why these differences?

    Why Ext.getStore('...'); to get a Store and MyAppName.app.getController('...'); to get a controller and not both Ext. or MyAppName.app.?

    MyAppName is not good since it can change. If it changes, we must change all occurrences.

  10. #9
    Sencha User interfasys's Avatar
    Join Date
    Mar 2011
    Location
    UK & Switzerland
    Posts
    125

    Default

    I agree with the last commenter.
    Basic method names should be predictable, even if calling a controller directly is not the best way to do things.
    And "this.getApplication()" should be available everywhere.
    Olivier - interfaSys
    Developing custom solutions for BlackBerry 10 using Sencha Touch.

  11. #10
    Touch Premium Member BostonMerlin's Avatar
    Join Date
    Aug 2010
    Location
    Boston
    Posts
    559
    Answers
    22

    Default

    ++ agree. Getting a controller reference should work exactly the same regardless of where you're calling from... a view or from within a controller. Anti-intuitive.



    Quote Originally Posted by interfasys View Post
    I agree with the last commenter.
    Basic method names should be predictable, even if calling a controller directly is not the best way to do things.
    And "this.getApplication()" should be available everywhere.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •