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

 ̄綄美尐妖づ 提交于 2020-01-03 00:58:52

问题


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'
     }]
    });

回答1:


You could set up a mapping:

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


来源:https://stackoverflow.com/questions/6721598/sencha-touch-how-to-get-list-itemtpl-to-display-json-child-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!