-
5 Mar 2012 5:08 AM #1
Answered: Unable to restore state
Answered: Unable to restore state
Hello, there,
I've been working over a Sencha Touch application using Sencha Touch 2 RC2.
I have problem when I want to restore the state of the application based on an url param (id of a service), but when I use the list with services there is no such problem.
Store
ControllerCode:Ext.define('CC.store.Services', { extend: 'Ext.data.Store', requires: ['CC.model.Service'], config: { model: 'CC.model.Service', grouper: { id : 'CategoryGrouper', property: 'category'}, proxy : { type: 'ajax', url: 'data.php', reader: { type: 'json', rootProperty: 'services' } }, autoLoad: true, ... } });
I hope there is enough information given.Code:... routes: { 'service/:id' : 'showServiceById' } ... showServiceById : function (id) { var list = this.getServicesList(), store = list.getStore(), record = store.getById(id); if (!this.servicesContainer) { this.servicesContainer = Ext.widget('servicesContainer'); } if (!this.servicesInfo) { this.servicesInfo = Ext.widget('servicesInfo'); } if (!this.service) { this.service = Ext.widget('service'); } this.getServicesContainer().push(this.service); this.getServicesInfo().setRecord(record); }
Thank you!
-
Best Answer Posted by mitchellsimoens
Check to see if the store is loading. If it is then add a load listener to execute a 2nd method. If it's not, execute that 2nd method.
-
5 Mar 2012 6:18 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
- Answers
- 3102
So your problem is when you type in the URL with the hash it hits your route handler but the store isn't loaded correct?
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.
-
5 Mar 2012 6:22 AM #3
-
5 Mar 2012 6:24 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
- Answers
- 3102
Check to see if the store is loading. If it is then add a load listener to execute a 2nd method. If it's not, execute that 2nd method.
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.
-
5 Mar 2012 8:22 AM #5
New solution
New solution
Following the TouchStyle example I've found another solution:
In the config of the controller I've added
the ensureStoreLoad function is the same as in the exampleCode:before: {showServiceById: 'ensureStoreLoad' },
After this there is no problem getting the record from the storeCode:ensureStoreLoad: function (action) { var store = Ext.getStore('Services'); if (store.data.all.length) { action.resume(); } else { store.on('load', function () { action.resume(); }, this, { single: true }); } }
Code:var list = this.getServicesList(), store = list.getStore(), record = store.getById(this.id), records; records = Ext.Array.filter(store.data.all, function (record) { if (record.get('id') == id) { return record; } }, this); record = records[0];Last edited by mihata; 6 Mar 2012 at 4:11 AM. Reason: I've found better solution


Reply With Quote