2011-07-17 63 views
1

我有一些問題試圖使用itemtpl屬性顯示子對象列表。這裏是問題的一個例子Sencha Touch - 如何獲取列表itemtpl以顯示JSON子對象?

JSON字符串:

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

型號:

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

商店:

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

列表:

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

回答

2

你可以建立一個映射:

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

謝謝!!!!!就像在我的頭上跳動,我知道它很簡單,我一直在努力。 – DvideBy0