Search code examples
ruby-on-rails-3extjsjsonstore

extjs nested json store rails


i am trying to post ext js json store that has some hard coded records.. there is one-to-many relationship between Customer & Product..

{
    "customers": [
        {
            "id": 123,
            "name": "Ed",
            "products": [
                {
                    "id": 50,
                    "prodnm": "xyz",
                     rate:20,
                },
                {
                    "id": 60,
                    "prodnm": "abc",
                     rate:30,
                }                    
            ]
        }
    ]
}

iam using rails & want to check whether i m getting proper json response..plz help..


Solution

  • For that you can use this code to get the json from store.

    function getJsonOfStore(store){
        var datar = new Array();
        var jsonDataEncode = "";
        var records = store.getRange();
        for (var i = 0; i < records.length; i++) {
            datar.push(records[i].data);
        }
        jsonDataEncode = Ext.util.JSON.encode(datar);
        return jsonDataEncode;
    }
    

    print that json in console then copy that json and past it here, click on format it will show you a formated json.