Threaded View

  1. #1
    Sencha User
    Join Date
    Nov 2009
    Location
    Milton Keynes, England
    Posts
    18
    Answers
    2
    Vote Rating
    0
    tomearly is on a distinguished road

      0  

    Question Answered: Store Sync Response

    Answered: Store Sync Response


    Hi,

    I have a Ext.data.Store on which I doing a sync.

    My sync works ok and I return some JSON. I can see the response in Firebug, but how do I use the response JSON?

    I've looked at the examples, looked through the forum and the internet, but cannot see how to do this.

    Below is the code I use for my store. If anyone is interested, i'm using the Bryntum Scheduler.

    PHP Code:
    eventStore Ext.create("Ext.data.Store", {
                                    
    idProperty 'Id',
                                    
    model 'Sch.model.Event2',
                                    
    autoLoadtrue,
                                    
    proxy: {
                                           
    type'ajax',
                                           
    api: {
                                                
    create'/cgi-bin/EV_Rostering_Shifts_Save_New.pl'// Called when saving new records
                                                
    read'/cgi-bin/EV_Rostering_Events_Get.pl?branch=' branch '&view=' view,
                                                
    update'/cgi-bin/EV_Rostering_Shifts_Save_Update.pl'// Called when updating existing records
                                                
    destroy'myBackend.php?action=destroy' // Called when deleting existing records
                                           
    },
                                           
    reader: {
                                                    
    type'json',
                                                    
    model 'Sch.model.Event2'
                                           
    },
                                           
    writer: new Ext.data.JsonWriter({
                                                    
    encode:         true,
                                                    
    writeAllFieldstrue,
                                                    
    root'data'
                                           
    }),
                                           
    timeout10000
                                    
    },
                                    
    listeners: {
                                            
    //add
                                            
    add: function(storerecordsindexoptions)
                                            {
                                            },
                                            
    update: function(storerecordsindexoptions)
                                            {
                                            }
                                            
    //remove
                                            //update
                                    
    }
                                }), 

  2. I've worked it out.

    I've added an exception listener to the store and can then access the response upon syncing the store.

    Something like this:-

    PHP Code:
    eventStore Ext.create("Ext.data.Store", {
                                    
    idProperty 'Id',
                                    
    model 'Sch.model.Event2',
                                    
    autoLoadtrue,
                                    
    proxy: {
                                           
    type'ajax',
                                           
    api: {
                                                
    create'/cgi-bin/EV_Rostering_Shifts_Save_New.pl'// Called when saving new records
                                                
    read'/cgi-bin/EV_Rostering_Events_Get.pl?branch=' branch '&view=' view,
                                                
    update'/cgi-bin/EV_Rostering_Shifts_Save_Update.pl'// Called when updating existing records
                                                
    destroy'myBackend.php?action=destroy' // Called when deleting existing records
                                           
    },
                                           
    reader: {
                                                    
    type'json',
                                                    
    model 'Sch.model.Event2'
                                           
    },
                                           
    writer: new Ext.data.JsonWriter({
                                                    
    encode:         true,
                                                    
    writeAllFieldstrue,
                                                    
    root'data'
                                           
    }),
                                           
    timeout10000,
                                            
    listeners: {
                                                    
    exception: function(proxyres) {
                                                            
    //console.log(proxy);
                                                            //console.log(type);
                                                            
    var responseObj Ext.JSON.decode(res.responseText);
                                                            var 
    success responseObj.success;

                                                            if(
    success == true)
                                                            {
                                                                    
    EV.Rostering.Grid.eventStore.commitChanges();
                                                                    
    EV.Rostering.Grid.eventStore.load();
                                                            }
                                                            else
                                                            {
                                                                    
    alert('Unable to save shift(s)');
                                                            }
                                                    }
                                            }
                                    }
                                }) 

Thread Participants: 1