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

      0  

    Default load multiple stores using a json with multiple roots

    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 Premium Member
    Join Date
    Jan 2010
    Location
    Vancouver, Canada
    Posts
    137
    Vote Rating
    29
    bogc will become famous soon enough bogc will become famous soon enough

      0  

    Default


    First of all, if you want someone to help you, you need to post your code, so we can reproduce the problem and give you the proper answer.

    I can tell you that loadRawData works - I used it many times.

    Now my advice is this. You said that one store is dependent on the other. Can you model the stores in a parent - child relationship? If that is the case, then you can populate only one store and the child data will be populated automatically (you need to include the child data in the parent, though).

    If that is not the case, then I wouldn't follow the pattern from that page. First, the stores in their sample have the same structure (is that your case as well??). You can simply make an ajax call that gets the data for both stores and use loadRawData to load the stores data. You don't really need a third store. However, as I am writing this I was thinking that the approach in the article might work, but the parent store (mainStore from the sample) would return a row with two fields each field containing the data for the respective store.

    To conclude, it would be better if you post your sample.

    cheers

  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 :

    // 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 :
    {
    "list": {
    "licenseData": [
    {
    "id": "abc",
    "text": "abc"
    }
    ]
    },
    "totalCount": "1",
    "list": {
    "featureData": [
    {
    "id": "23",
    "name": "xyz"
    }
    ]
    }
    }

    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

Thread Participants: 1

Tags for this Thread