Results 1 to 5 of 5

Thread: Unable to restore state

  1. #1
    Sencha User
    Join Date
    Jan 2011
    Posts
    3
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Jan 2011
    Posts
    3
    Vote Rating
    0
      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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  6. #5
    Sencha User
    Join Date
    Jan 2011
    Posts
    3
    Vote Rating
    0
      0  

    Default 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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •