1. #1
    Sencha User
    Join Date
    Dec 2012
    Posts
    10
    Vote Rating
    0
    ronana is on a distinguished road

      0  

    Default nested JSON data - can't find child data

    Hi there, really stuck on this, seen quite a few threads on this, but still not working.

    I need to read the coverImageURL from nested JSON data... ie. using the mapping:blockofResults.itemCoverImage.coverImageURL
    I've also tried using hasOne association but no luck there either.

    Code:
    Code:
    Ext.define('MyApp.model.ItemCoverImage', {
        extend: 'Ext.data.Model',
        config: {
            fields: [{
                name: 'coverImageURL'
            }]
        }
    });
    Code:
    Code:
    Ext.define('MyApp.model.SearchResult', {
        extend: 'Ext.data.Model',
        uses: ['MyApp.model.ItemCoverImage'],
        config: {
            fields: [{
                name: 'title'
            }, {
                name: 'coverImageURL',
                mapping: 'itemCoverImage.coverImageURL'
            }],
            hasOne: {
                model: 'MyApp.model.ItemCoverImage'
            },
            proxy: {
                type: 'jsonp',
                batchActions: false,
                url: '####search?searchTerms=we&getThumbnails',
                autoAppendParams: false,
                reader: {
                    type: 'json',
                    rootProperty: 'blockOfResults',
                    useSimpleAccessors: true
                }
            }
        }
    });
    Code:
    Code:
    Ext.define('MyApp.store.SearchStore', {
        extend: 'Ext.data.Store',
        requires: ['MyApp.model.SearchResult'],
        config: {
            autoLoad: true,
            model: 'MyApp.model.SearchResult',
            storeId: 'SearchStore'
        }
    });
    Code:
    Code:
    Ext.define('MyApp.view.MyList', {
        extend: 'Ext.dataview.List',
        config: {
            store: 'SearchStore',
            itemTpl: ['<div> {title}</div>', '<div> {coverImageURL}  ', '      </div>'],
            listeners: [{
                fn: 'onListShow',
                event: 'show'
            }]
        },
        onListShow: function (component, options) {
            var store = Ext.StoreManager.get('SearchStore'); 
            //store.load();        
            console.log(store);        
            console.log(store.data);    
        }
    });
    the JSON to be consumed is:
    Code:
    Code:
    {
        "returnCode": 0,
        "searchResultsKey": -465714508,
        "numberOfResults": 178,
        "blockOfResults": [
            {
                "itemCoverImage": {
                    "coverImageURL": "http://ecx.images-amazon.com/images/I/517GB06BN6L._SL75_.jpg"
                },
                "title": "'I don't care!' said the bear"
            }
        ]
    }
    Last edited by aconran; 20 Feb 2013 at 6:40 PM. Reason: post formatting with code tags

  2. #2
    Sencha User aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,485
    Vote Rating
    136
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default

    You do not need to use associations.

    You just need to set your mapping to itemCoverImage.coverImageURL.

    Do not include the rootProperty in your mapping.
    Aaron Conran
    @aconran

  3. #3
    Sencha User
    Join Date
    Dec 2012
    Posts
    10
    Vote Rating
    0
    ronana is on a distinguished road

      0  

    Default

    Thanks for the response. It doesn't work still.

    What I notice is that when I load the store data, inside architect, then I can't see the nested data.

    I have tried with autoload = true and also store.load();

    I am trying to use the override mentioned in this thread:

    http://www.sencha.com/forum/showthre...id-Store/page2

    ... but I'm not sure what the format for overrides should be in architect.

    perhaps there is something wrong with my json?

    Code:
    proxy: {            type: 'jsonp',
                url: 'http://www.accessitsoftware.com:2011/json/search?searchTerms=we&getThumbnails',
                reader: {
                    type: 'json',
                    rootProperty: 'blockOfResults',
                    useSimpleAccessors: true
                }
            }

  4. #4
    Sencha User aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,485
    Vote Rating
    136
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default

    Ah, I missed that you had useSimpleAccessors set to true. You need to turn that off!

    http://docs.sencha.com/ext-js/4-1/#!...impleAccessors

    That would basically be if you literally had that as your key.

    Code:
    {
       "itemCoverImage.coverImageURL": "theurl"
    }
    Aaron Conran
    @aconran

  5. #5
    Sencha User
    Join Date
    Dec 2012
    Posts
    10
    Vote Rating
    0
    ronana is on a distinguished road

      0  

    Default

    Thanks for clarifying

    I found the issue now.. turns out the server wasn't sending the correct response.

    Much Appreciated!!

    Ronan

  6. #6
    Sencha User
    Join Date
    Mar 2013
    Location
    India
    Posts
    7
    Vote Rating
    0
    sharikank is on a distinguished road

      0  

    Default

    what if my json looks like this?


    Code:
    {
        "EmployeeLeaves": {
            "ID": 37,
            "LeaveHistory": [
                {
                    "ApprovedBy": 12,
                    "Duration": 3
                },
                {
                    "ApprovedBy": 12,
                    "Duration": 1
                },
                {
                    "ApprovedBy": 0,
                    "Duration": 2
                },
                {
                    "ApprovedBy": 2,
                    "Duration": 5
                }
            ],
            "PLavailedcount": 2
        }
    }

  7. #7
    Sencha User aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,485
    Vote Rating
    136
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default

    Your root is EmployeeLeaves.LeaveHistory
    Aaron Conran
    @aconran

  8. #8
    Sencha User
    Join Date
    Mar 2013
    Location
    India
    Posts
    7
    Vote Rating
    0
    sharikank is on a distinguished road

      0  

    Default

    Quote Originally Posted by aconran View Post
    Your root is EmployeeLeaves.LeaveHistory
    The problem is i have to populate two grids with the same json and do other operations like add new leave and edit or cancel.One grid should be using LeaveHistory and the other LeaveEliginility.Can't that be done using associations?Is that even possible?

    My original JSON

    {
    "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
    }
    }

  9. #9
    Sencha User
    Join Date
    Mar 2013
    Location
    India
    Posts
    7
    Vote Rating
    0
    sharikank is on a distinguished road

      0  

    Default Nested Json for two grids

    Quote Originally Posted by aconran View Post
    Your root is EmployeeLeaves.LeaveHistory
    please help me with this

    http://www.sencha.com/forum/showthread.php?259851-Nested-Json-for-populating-two-grids.&p=951761#post951761

    D
    o i have to use separate stores for the two grids ? Then what will i do when i have to add a new leave or edit with the json and reflect the same in the grids

  10. #10
    Sencha User aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,485
    Vote Rating
    136
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default

    Hrm, they don't really look like they are associated with one another

    It seems what you want to do is setup 2 different stores and then use a single Ajax request to load them.

    Something like:
    Code:
    Ext.Ajax.request({
       url: 'myUrl',
       success: fucntion(response, opts) {
          store1.loadData(o.LeaveElibility);
          store2.loadData(o.LeaveHistory);
       }
    });
    And then obviously you don't need to set a root at all.
    Aaron Conran
    @aconran

Thread Participants: 2