Populating Grids with nested json

  1. sharikank
    sharikank
    I have a json like this..
    Code:
    {
        "EmployeeLeaves": {
            "ID": 37,
            "LeaveEligibility": [
                {
                    "Availed": 4,
                    "Fullpaydays": 6,
                    "Halfpaydays": 0,
                    "ID": 1,
                    "LeaveTypeId": 60,
                    "PersonId": 37,
                    "YearOfLeave": 2013
                },
                {
                    "Availed": 2,
                    "Fullpaydays": 6,
                    "Halfpaydays": 0,
                    "ID": 3,
                    "LeaveTypeId": 61,
                    "PersonId": 37,
                    "YearOfLeave": 2013
                },
                {
                    "Availed": 10,
                    "Fullpaydays": 10,
                    "Halfpaydays": 0,
                    "ID": 4,
                    "LeaveTypeId": 62,
                    "PersonId": 37,
                    "YearOfLeave": 2013
                },
                {
                    "Availed": 0,
                    "Fullpaydays": 8,
                    "Halfpaydays": 0,
                    "ID": 6,
                    "LeaveTypeId": 63,
                    "PersonId": 37,
                    "YearOfLeave": 2013
                }
            ],
            "LeaveHistory": [
                {
                    "AppliedTo": "Vibha",
                    "ApprovalDate": "3/12/2013 12:00:00 AM",
                    "ApprovedBy": 12,
                    "Duration": 3,
                    "FromDate": "3/24/2013 12:00:00 AM",
                    "FullPayDays": 3,
                    "HalfPayDays": 0,
                    "ID": 1,
                    "LeaveTypeId": 60,
                    "LossOfPayDays": 0,
                    "PersonId": 37,
                    "Remarks": "onnulla",
                    "StatusId": 79,
                    "SubstitutePersonId": 13,
                    "ToDate": "3/26/2013 12:00:00 AM"
                },
                {
                    "AppliedTo": "Vibha",
                    "ApprovalDate": "3/12/2013 12:00:00 AM",
                    "ApprovedBy": 12,
                    "Duration": 1,
                    "FromDate": "3/30/2013 12:00:00 AM",
                    "FullPayDays": 1,
                    "HalfPayDays": 0,
                    "ID": 2,
                    "LeaveTypeId": 60,
                    "LossOfPayDays": 0,
                    "PersonId": 37,
                    "Remarks": "onnulla",
                    "StatusId": 79,
                    "SubstitutePersonId": 13,
                    "ToDate": "3/31/2013 12:00:00 AM"
                },
                {
                    "AppliedTo": "Shyam",
                    "ApprovalDate": "",
                    "ApprovedBy": 0,
                    "Duration": 2,
                    "FromDate": "2/13/2013 12:00:00 AM",
                    "FullPayDays": 2,
                    "HalfPayDays": 0,
                    "ID": 4,
                    "LeaveTypeId": 61,
                    "LossOfPayDays": 0,
                    "PersonId": 37,
                    "Remarks": "blha blah",
                    "StatusId": 70,
                    "SubstitutePersonId": 1,
                    "ToDate": "2/14/2013 12:00:00 AM"
                },
                {
                    "AppliedTo": "Shyam",
                    "ApprovalDate": "2/13/2013 4:35:16 PM",
                    "ApprovedBy": 2,
                    "Duration": 5,
                    "FromDate": "3/23/2013 12:00:00 AM",
                    "FullPayDays": 5,
                    "HalfPayDays": 0,
                    "ID": 5,
                    "LeaveTypeId": 62,
                    "LossOfPayDays": 0,
                    "PersonId": 37,
                    "Remarks": "oh..",
                    "StatusId": 71,
                    "SubstitutePersonId": 1,
                    "ToDate": "3/27/2013 12:00:00 AM"
                },
                {
                    "AppliedTo": "Shyam",
                    "ApprovalDate": "2/13/2013 4:35:16 PM",
                    "ApprovedBy": 2,
                    "Duration": 5,
                    "FromDate": "3/28/2013 12:00:00 AM",
                    "FullPayDays": 5,
                    "HalfPayDays": 0,
                    "ID": 6,
                    "LeaveTypeId": 62,
                    "LossOfPayDays": 0,
                    "PersonId": 37,
                    "Remarks": "oh..",
                    "StatusId": 71,
                    "SubstitutePersonId": 1,
                    "ToDate": "3/29/2013 12:00:00 AM"
                }
            ],
            "PLavailedcount": 2
        }
    }
    I need to populate two grids using the data in LeaveHistory and LeaveEligibility.I have tried using associations
    My models are
    Code:
    Ext.define('AM.model.EMPLeaveHistory', {
        extend : 'Ext.data.Model',
        config : {
            idProperty : 'ID',
            fields: [{
                name: 'Duration'
                    }, {
                name: 'ApprovedBy'
                   }]
        }
    });
    
    Ext.define('AM.model.EMPLeaveRequest', {
        extend: 'Ext.data.Model',
        config: {
            fields  : [
                {
                    name : 'ID',
                    type : 'int'
                },
                {
                    name : 'PlAvailedCount'
                }
            ],
            hasMany : [
                {
                    model          : 'AM.model.EMPLeaveHistory',
                    name           : 'LeaveHistory',
                    associationKey : 'LeaveHistory'
                }
            ]
        }
    });
    My store is..
    Code:
    Ext.define('AM.store.EMPLeaveRequest', {
        extend: 'Ext.data.JsonStore',
        model: 'AM.model.EMPLeaveRequest',
            autoLoad: true,
         proxy: {
                type: 'ajax',
               
                url: 'data/employeeleave.json',
                autoAppendParams: false,
                reader: {
                    type: 'json'
                    ,root:'EmployeeLeaves'
                         }
            }
    });
Results 1 to 1 of 1