1. #1
    Sencha User
    Join Date
    Feb 2013
    Posts
    5
    Vote Rating
    0
    AndrewCrofts is on a distinguished road

      0  

    Default Answered: Why does my JSON download into store need two button taps?

    Answered: Why does my JSON download into store need two button taps?


    I am downloading data via a PHP script in JSON format using the following store and models:

    Code:
    Ext.define('CarCheck.store.JobsJSONStorage', {
        extend: 'Ext.data.Store',
        requires: ['Ext.data.proxy.Ajax', 'Ext.data.reader.Json'],
        config: {
            autoLoad: false,
            storeId: 'jobsStoreJSONStorage',
            model: 'CarCheck.model.Job',
            proxy: {
                type: 'ajax',
                url: 'download.php',
                enablePagingParams: false,
                reader: {
                    type: 'json',
                    rootProperty: 'Jobs'
                }
            }
        }
    });
    Code:
    Ext.define('CarCheck.model.Job', {
        extend: 'Ext.data.Model',
    
    
        config: {
            identifier: 'uuid',
            fields: [
                {name: 'id',    type: 'auto'},
                {name: 'JobNo', type: 'string'},
                {name: 'RegNo', type: 'string'}
            ],
            hasMany: {model: 'CarCheck.model.JobLine', name: 'jobLines', associationKey: 'JobLines'}
        }
    });
    Code:
    Ext.define('CarCheck.model.JobLine', {
        extend: 'Ext.data.Model',
        config: {
            identifier: 'uuid',
            fields: [
                {name: 'id',           type: 'auto'},
                {name: 'job_id',       type: 'auto'},
                {name: 'JobNo',        type: 'string'},
                {name: 'JobLine',      type: 'string'},
                {name: 'ItemSequence', type: 'string'},
                {name: 'InspectorID',  type: 'string'},
                {name: 'Status',       type: 'string'},
                {name: 'ItemDesc',     type: 'string'},
                {name: 'Comments',     type: 'string'},
                {name: 'InspDateTime', type: 'string'},
                {name: 'DeviceID',     type: 'string'},
                {name: 'TLA',          type: 'string'}
            ],
            belongsTo: 'Job'
        }
    });
    The download is initiated via a button tap in a controller file, which calls the following function:

    Code:
        SyncData: function() {
    
    
            var jobsStore = Ext.getStore('jobsStoreJSONStorage');
    
    
            var formData = this.getSettingsform();
            var dataRecord = formData.getValues();
    
    
            jobsStore.getProxy().setExtraParams({
                tla: dataRecord.companyId,
                deviceId: dataRecord.deviceId
            });
    
    
            jobsStore.load();
    
    
            console.log(jobsStore.getAllCount());
        },
    This all works fine, except not the first time the download button is tapped.

    The first time the JSON file is received from the PHP script, so the problem seems to be at the jobsStore.load() line. Is there something I need to do to get it work first time?

    Sorry, I've put this in the wrong place!!! Will move it the Sencha Touch 2 forum.
    Last edited by AndrewCrofts; 5 Feb 2013 at 3:22 AM. Reason: Wrong Thread

  2. If you are checking the count of store (console.log(jobsStore.getAllCount()) after your jobsStore.load();, then you might not get correct data. You need to wait till your store loads.

    try following

    Code:
    jobsStore.load({
        callback : function(){
              console.log(jobsStore.getAllCount());
        }
    
    });
    

  3. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,617
    Answers
    612
    Vote Rating
    396
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Moved.

    Scott

  4. #3
    Sencha User
    Join Date
    Jul 2012
    Posts
    48
    Answers
    4
    Vote Rating
    3
    shwetapande10 is on a distinguished road

      0  

    Default


    If you are checking the count of store (console.log(jobsStore.getAllCount()) after your jobsStore.load();, then you might not get correct data. You need to wait till your store loads.

    try following

    Code:
    jobsStore.load({
        callback : function(){
              console.log(jobsStore.getAllCount());
        }
    
    });
    

Thread Participants: 2

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar