1. #1
    Sencha User
    Join Date
    Jan 2011
    Posts
    3
    Vote Rating
    0
    mihata is on a distinguished road

      0  

    Default 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
    Code:
    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,
            ...
        }
    });
    Controller
    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);
        }
    I hope there is enough information given.
    Thank you!

  2. 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.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Answers
    3541
    Vote Rating
    847
    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


    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
    ________________
    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.

  4. #3
    Sencha User
    Join Date
    Jan 2011
    Posts
    3
    Vote Rating
    0
    mihata is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    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?
    Exactly.
    I see the animation and the "sub page" is loaded but without any content.

  5. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Answers
    3541
    Vote Rating
    847
    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


    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
    ________________
    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.

  6. #5
    Sencha User
    Join Date
    Jan 2011
    Posts
    3
    Vote Rating
    0
    mihata is on a distinguished road

      0  

    Default New solution

    New solution


    Following the TouchStyle example I've found another solution:
    In the config of the controller I've added
    Code:
    before: {showServiceById: 'ensureStoreLoad' },
    the ensureStoreLoad function is the same as in the example
    Code:
    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
            });
        }
    }
    After this there is no problem getting the record from the store
    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

Thread Participants: 1

Tags for this Thread