-
17 Aug 2012 1:35 PM #1
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.
Console error:Code:document.addEventListener("keyup", onKeyUp, false); function onKeyUp() { console.log('back'); this.getMainNav().pop(); // doesn't work }
Uncaught TypeError: Object function () {
return this.constructor.apply(this, arguments);
} has no method 'pop'
-
Best Answer Posted by mitchellsimoens
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()); } }
-
19 Aug 2012 6:10 PM #2
I am still having this issue, has anyone dealt with this before?
-
20 Aug 2012 5:31 AM #3Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
- Answers
- 3101
Look to see what getMainNav() returns. Is there a reference already created to match your ref?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
20 Aug 2012 5:46 AM #4
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:
Logs: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()); } } });
Uncaught TypeError: Object #<HTMLDocument> has no method 'getMainNav'
-
20 Aug 2012 5:51 AM #5Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
- Answers
- 3101
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
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
20 Aug 2012 5:54 AM #6
So that's what that does! This solves so many of my issues. You've saved me yet again, thank you.


Reply With Quote