DvideBy0
DvideBy0

Reputation: 688

Sencha Touch - How to get list itemtpl to display JSON child objects?

I am having some problems trying to display child objects using itemtpl property for a list. here is an example of the issue

JSON String:

{"messages" : [{"body":{"special":"some special format", "plain":"plain format"}}]

Model:

Ext.regModel('MyFeed', {
        fields: [
            {name: 'body'}
        ]
    });

Store:

var FeedStore = new Ext.data.Store({
        model: 'MyFeed',
        proxy: {
            type: 'ajax',
            url: 'data.json',
            reader: {
                type: 'json',
                root: 'messages'
            }
        }
    });

List:

var FeedList = new Ext.List({
        itemTpl : '<div>{body}</div>',
        store: FeedStore,
        width: '100%',
        style: 'background-color: #dfe2e3',
     plugins: [{
        ptype: 'pullrefresh'
     }]
    });

Upvotes: 1

Views: 4437

Answers (1)

Evan Trimboli
Evan Trimboli

Reputation: 30092

You could set up a mapping:

Ext.regModel('MyFeed', {
    fields: [
        {name: 'body'},
        {name: 'special', mapping: 'body.special'},
        {name: 'plain', mapping: 'body.plain'}
    ]
});

Upvotes: 2

Related Questions