1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    30
    Vote Rating
    0
    namrms is on a distinguished road

      0  

    Default Unanswered: load multiple stores using a json with multiple roots

    Unanswered: load multiple stores using a json with multiple roots


    Hi ,

    I have two stores. One being dependent on the other. Hence I would like to fire a query to the database only once and use the same json to load both the stores .

    I tried doing the same as suggested in the link : http://www.hightechinthehub.com/2012...ingle-request/


    However I am getting an error that loadRawData() doesnt exist. Using loadData() is not helping either.

    I am using Ext Version 4.0 . The documentations describes the method however. Please suggest how to go about.

    Regards,
    Namratha

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,112
    Answers
    678
    Vote Rating
    470
    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


    You would need to show some code .. should like you have a invalid store object ..

    should work something like:

    Code:
    // main app store
    var mainStore = new Ext.data.Store({
    });
     
    // loader store for new data; append records to main
    var loadStore = new Ext.data.Store({
    	listeners: {
    		load: function(store, records, successful) {
    			mainStore.loadData(records,true); // true = append records to main
    		}	
    	}
    });
    Scott.

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    30
    Vote Rating
    0
    namrms is on a distinguished road

      0  

    Default


    Hi ,


    Here is the sample code :

    Code:
    // The below store can be considered as a sub store.
    var licenseJStore = new Ext.data.ArrayStore({
    fields: ['id','text'], 
    proxy : {
    type : 'memory', 
    reader : {
    type : 'json',
    root : 'list.licenseData'
    }
    },
    autoLoad : false,
    listeners :{
    load :{
    fn : function(){
    alert('store loaded');
    }
    }
    }
    });
    
    
    // The main store :
    var featureJStore = new Ext.data.Store(
    {
    model : 'featureRecord',
    pageSize : 500,
    proxy : {
    type : 'ajax',
    url : 'featureList.data',
    timeout : 300000,
    reader : {
    type : 'json',
    root : 'list.featureData',
    totalProperty : 'totalCount'
    },actionMethods : {
    read : 'POST'
    }
    },
    listeners : {
    load : {
    fn : function(thisStore) {
    alert(thisStore.proxy.reader.jsonData); // valid object
    licenseJStore.loadRawData(thisStore.proxy.reader.jsonData);
    }
    } 
    }, 
    autoLoad : false
    });
    The JSON is of the form :
    Code:
    {
        "list": {
            "featureData": [
                {
                    "id": "23",
                    "name": "xyz"
                }
            ]
        },
        "totalCount": "1"
    }
    The Error Message :
    TypeError: licenseJStore.loadRawData is not a function
    Line 1885
    Also Does loadRawData() trigger the load event on the store ?

    I am using the feature store to load my grid and license store to load the list filter of the same grid.
    Since for the list filter to work load event is required let me know if this approach will work ?


    Thanks and Regards,
    Namratha

  4. #4
    Sencha User
    Join Date
    Oct 2012
    Posts
    30
    Vote Rating
    0
    namrms is on a distinguished road

      0  

    Default


    In the above example that I have pasted, I want the list.featureData to be loaded into the featureStore and list.licenseData into the license store.

  5. #5
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,112
    Answers
    678
    Vote Rating
    470
    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


    Set your licenseJStore to Ext.data.Store instead of Ext.data.ArrayStore and see if that helps.

    Scott

  6. #6
    Sencha User
    Join Date
    Oct 2012
    Posts
    30
    Vote Rating
    0
    namrms is on a distinguished road

      0  

    Default


    Hi Scott,

    It doesnt help either . I get the same error.

    Regards,
    Namratha

  7. #7
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,112
    Answers
    678
    Vote Rating
    470
    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


    You did not change the type from memory to ajax.

    Duplicate the other store settings.

  8. #8
    Sencha User
    Join Date
    Oct 2012
    Posts
    30
    Vote Rating
    0
    namrms is on a distinguished road

      0  

    Default


    It doesnt help even after replicating the settings for the store.
    Here are the settings that I did for the dependent store :

    var licenseJStore = new Ext.data.Store({
    fields: ['id','text'],
    proxy : {
    type : 'ajax',
    url : 'LicenseList.data',
    timeout : 180000,
    reader : {
    type : 'json',
    root : 'list.licenseData'
    },


    actionMethods : {
    read : 'POST'
    }
    },
    autoLoad : false

    });

  9. #9
    Sencha User
    Join Date
    Oct 2012
    Posts
    30
    Vote Rating
    0
    namrms is on a distinguished road

      0  

    Default


    Hi ,

    I was able to get this working by using the below approach .

    Both the stores have a similar settings. Instead of using loadRawData , I am using the loadData() as below :

    licenseJStore.loadData(thisStore.proxy.reader.jsonData.list1.licenseData); - This statement is in the load event of the main store.


    json is of the form{"totalCount": "111","list1":{"licenseData":[{"id":"1","text":"hello"},{"id":"2","text":"world"}]},"list":{"featureData":[{"id":"feature1"},{"id":"feature2"}]}

Thread Participants: 1

Tags for this Thread