1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    7
    Vote Rating
    0
    mack30 is on a distinguished road

      0  

    Default Unanswered: JSONReader and anonymous parent array (moved from extJS 4)

    Unanswered: JSONReader and anonymous parent array (moved from extJS 4)


    I've not been able to determine how to read the following server data via a json reader and display it in a list.

    The server data is a single element anonymous array that wraps an array of Message. I am interested in the inner Message array.

    Code:
    [
        {"Message": 
          [
            {
                "messageID": "3701",
                "msgTypeID":"2", 
                "title": "Alpha"
            },
            {
                "messageID": "3702",
                "msgTypeID":"2", 
                "title": "Beta"
            }    
          ]
        }
    ]


    I am using the Tweets page of the Sencha Touch O'Reilly example as the base of my experiments. The view look likes this:

    Code:
            itemTpl: Ext.create('Ext.XTemplate',
                    'hello ',
                     '<h2>{messageID} {title}</h2>'
            )



    and the Store looks like this:
    Code:
    Ext.define('Oreilly.store.Tweets', {
        extend: 'Ext.data.Store',
    
        config: {
            fields: ['messageID',  'msgTypeID', 'title'],
            proxy: {
                type: 'ajax',
                url: 'http://myserver/messages',
                headers: {
                    'MyHeader': 'abc123'
                },
    
    
                reader: { 
                    type: 'json', 
                    rootProperty: '[0].Message' 
                } 
    
    
    
    
            }
        }
    });


    Any help will be appreciated.

    Attached Images

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    Answers
    3575
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You really need to change your JSON to be like:

    Code:
    {
        "Message": [
            {
                "messageID": "3701",
                "msgTypeID": "2",
                "title": "Alpha"
            },
            {
                "messageID": "3702",
                "msgTypeID": "2",
                "title": "Beta"
            }
        ]
    }
    If not then you may need to create your own json reader extension to handle it.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Ext JS Premium Member
    Join Date
    Aug 2011
    Posts
    37
    Vote Rating
    0
    Answers
    1
    jakobgrannas is on a distinguished road

      0  

    Default


    I have the same problem, and I can't change the JSON structure since I get my data from an external source. Is there really no other way than to create an extension?

  4. #4
    Sencha User
    Join Date
    Apr 2012
    Posts
    7
    Vote Rating
    0
    mack30 is on a distinguished road

      0  

    Default


    I am stuck with this nested array structure for now as our current mobile app uses it, but would welcome any tips you might offer to get me started on a reader extension. Thank you.

Thread Participants: 2

Tags for this Thread