1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    45
    Answers
    2
    Vote Rating
    0
    cooperka is on a distinguished road

      0  

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

    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
    cooperka is on a distinguished road

      0  

    Default


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

  4. #3
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,347
    Answers
    3542
    Vote Rating
    846
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Look to see what getMainNav() returns. Is there a reference already created to match your ref?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #4
    Sencha User
    Join Date
    Jun 2012
    Posts
    45
    Answers
    2
    Vote Rating
    0
    cooperka is on a distinguished road

      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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,347
    Answers
    3542
    Vote Rating
    846
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  7. #6
    Sencha User
    Join Date
    Jun 2012
    Posts
    45
    Answers
    2
    Vote Rating
    0
    cooperka is on a distinguished road

      0  

    Default


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

Thread Participants: 1

Tags for this Thread