Results 1 to 6 of 6

Thread: How to trigger NavigationView.pop() from onKeyUp listener

  1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    45
    Answers
    2
    Vote Rating
    0
      0  

    Default Answered: How to trigger NavigationView.pop() from onKeyUp listener

    I am trying to listen for a "keyup" event at any time and on any screen of my app. If such an event occurs, I want my NavigationView to pop() -- the same thing that would happen if the user were to tap the Back button.

    In my controller "launch" function I have the following code. How can I get a reference to the NavigationView so I can call pop()? this.getMainNav() works in my other controllers for List itemtaps.
    Code:
    document.addEventListener("keyup", onKeyUp, false);
    function onKeyUp() {
        console.log('back');
        this.getMainNav().pop(); // doesn't work
    }
    Console error:
    Uncaught TypeError: Object function () {
    return this.constructor.apply(this, arguments);
    } has no method 'pop'

  2. That error is saying you have a scoping issue.

    Code:
        launch: function() {
            var me = this;
    
            Ext.Viewport.add({
                xclass: 'MyApp.view.MainNav'
            });
    
    
            // listen for back button
            document.addEventListener("backbutton", onBackKeyDown, true);
    
    
            // for testing purposes in browser
            document.addEventListener("click", onBackKeyDown, true);
    
    
            function onBackKeyDown() {
                console.log(me.getMainNav());
            }
        }

  3. #2
    Sencha User
    Join Date
    Jun 2012
    Posts
    45
    Answers
    2
    Vote Rating
    0
      0  

    Default

    I am still having this issue, has anyone dealt with this before?

  4. #3
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      0  

    Default

    Look to see what getMainNav() returns. Is there a reference already created to match your ref?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  5. #4
    Sencha User
    Join Date
    Jun 2012
    Posts
    45
    Answers
    2
    Vote Rating
    0
      0  

    Default

    My "ref" and "selector" in the controller reference are both mainNav, as well as my userAlias and userClassName for the NavigationView (userClassName is MainNav with capital M). Do you mean I have to create another reference other than the controller?

    I'm also not sure what I changed, but the error is different now.

    The following code:
    Code:
    Ext.define('MyApp.controller.MyController', {
        extend: 'Ext.app.Controller',
    
    
        config: {
            refs: {
                mainNav: 'mainNav'
            },
    
    
        launch: function() {
            Ext.Viewport.add({
                xclass: 'MyApp.view.MainNav'
            });
    
    
            // listen for back button
            document.addEventListener("backbutton", onBackKeyDown, true);
    
    
            // for testing purposes in browser
            document.addEventListener("click", onBackKeyDown, true);
    
    
            function onBackKeyDown() {
                console.log(this.getMainNav());
            }
        }
    });
    Logs:
    Uncaught TypeError: Object #<HTMLDocument> has no method 'getMainNav'

  6. #5
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      1  

    Default

    That error is saying you have a scoping issue.

    Code:
        launch: function() {
            var me = this;
    
            Ext.Viewport.add({
                xclass: 'MyApp.view.MainNav'
            });
    
    
            // listen for back button
            document.addEventListener("backbutton", onBackKeyDown, true);
    
    
            // for testing purposes in browser
            document.addEventListener("click", onBackKeyDown, true);
    
    
            function onBackKeyDown() {
                console.log(me.getMainNav());
            }
        }
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  7. #6
    Sencha User
    Join Date
    Jun 2012
    Posts
    45
    Answers
    2
    Vote Rating
    0
      0  

    Default

    So that's what that does! This solves so many of my issues. You've saved me yet again, thank you.

Tags for this Thread

Posting Permissions

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