-
17 Apr 2012 7:11 AM #1
Routes example
Routes example
I want to use routes in secha touch 2 application. So it will be very helpful if any body can give simple examples on "how to use routes in sencha touch 2?".
-
17 Apr 2012 7:48 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 435
Couple of the examples like KitchenSink and TouchStyle use routes.
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.
-
18 Apr 2012 9:23 AM #3
The guide on History Support/Routes is given at http://docs.sencha.com/touch/2-0/#!/guide/history_support
Though I was just looking myself for simple route so I can direct a user to a specific card/view. So for my example, I did this inside the Controller for that View:
.. I know there must be a cleaner way or set view item based on the View name so incase I need to switch order, I don't have to go through and figure out the number on the tab itemsPHP Code:config:{
routes: {
'events': 'showCampusEvents'
// when user types in http://domain.com/#events , function is fired
}
},
showCampusEvents: function(){
Ext.ComponentManager.get("mainTabPanel").setActiveItem(2);
// after loading of application, controller is fired and changes the
// view to the Events view
}
-
18 Apr 2012 1:40 PM #4
My demo app contains a good example on how to use routes:
https://github.com/kostysh/Sencha-To...ith-NestedList
-
23 Apr 2012 6:57 AM #5
Thank you all, all the examples are very useful...
-
13 May 2012 4:16 PM #6
I would say you guys do a fair job of describing how to define things in the application and a most lousy job of describing how to use what has been defined.
function button_touched()
{
// need to navigate to a route, how to do it?
// document.location.href = "myroute"; perhaps?
// are routes
}
I have finally figured out the nifty idiom
document.location.href=document.location.href.split('#')[0]+'#user/12345';
or whatever the new route is - which seems to get me what I want.
-
14 May 2012 2:06 AM #7
@CarClub,
To redirect you can use
http://docs.sencha.com/touch/2-0/#!/api/Ext.app.Controller-method-redirectToCode:this.redirectTo('user/12345');
http://docs.sencha.com/touch/2-0/#!/...hod-redirectTo
-
14 May 2012 2:35 AM #8
-
14 May 2012 5:22 AM #9Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 435
redirectTo will not only change the hash but will check to see if you have a route handler created for it. If there isn't one then it won't change the hash.
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.
-
14 May 2012 1:47 PM #10
OK, so how do I put up a route handler that can deal with a form post? I'm missing something here.
form url="#login", method="post"
input name=username,
input name=password,
button, handler=function(){var form = this.up('formpanel'); form.submit(); }
create a route for 'login' : 'doLogin'
Ext.define('MyApp.controller.LoginController', {
extend: 'Ext.app.Controller',
config: {
routes: {
'login': 'doLogin'
},
refs: {
loginForm: {
selector: '#login_form',
xtype: 'formpanel'
}
}
},
doLogin: function() {
var form = Ext.getCmp('login_form');
var values = form.getValues();
this.getApplication().authenticate(values);
}
});
problem being, when doLogin has been called, page has been reloaded and form values are gone.
I want the action triggered from form.submit because it is possible to submit the form from the Android keyboard using the "GO" button.
This is very confusing - want to submit a form to a route via the form.submit action being triggered.


Reply With Quote