如何在extjs4中使用tpl显示嵌套的json

问题描述:

我正在extjs4 + yii框架中工作。我的服务器端在yii [php],客户端在extjs4。我从服务器端以json格式发送数据。 我有JSON原样如何在extjs4中使用tpl显示嵌套的json

{ 
    "data": { 
     "Meaning": [ 
      { 
       "Noun": "sea" 
      }, 
      { 
       "Adverb": "Null" 
      }, 
      { 
       "Adjective": "Null" 
      } 
     ], 
     "pronunciation": "sea", 
     "Media": [ 
      { 
       "image": "abc.jpg" 
      }, 
      { 
       "image": "xyz.jpg" 
      }, 
      { 
       "Video": "Windows Media Audio/Video file (.wmv)" 
      } 
     ] 
    } 
} 

我想显示在视图中使用TPL的ExtJS的这个JSON。那么如何使用extjs tpl显示这个嵌套的json呢?

+0

看一看这里: http://stackoverflow.com/questions/15253118/extjs-parsing-nested-json-in-template – PHP 2013-05-03 11:14:56

简单的解决方案:

Ext.widget('panel', { 
    renderTo: Ext.getBody() 
    // 4 is the number of indentation spaces 
    ,tpl: '<pre>{[JSON.stringify(values, null, 4)]}</pre>' 
    ,height: 400 
    ,data: ... // sample data 
});