1

我试图在我的模型中引用复杂的 json 对象,然后将它们与其他对象一起显示在表格中。下面是一个json的例子。如何获得评分和类型?

   "reviews" : [
     {
        "aspects" : [
           {
              "rating" : 1,
              "type" : "food"
           },
           {
              "rating" : 3,
              "type" : "decor"
           },
           {
              "rating" : 2,
              "type" : "service"
           }
        ]


Ext.define('FirstApp.model.Details',{
extend:'Ext.data.Model',
config:{
  //  fields:     ['id','recordId','name','icon','vicinity','reference','website','reviews.aspects.type'],


 fields: [ {

name: 'aspects',
mapping: 'reviews.aspects'
},
  {
  name: 'vicinity'
  },
    {
   name: 'name'
  },
  {
  name: 'icon'
  },
 {
  name: 'website'
  }]

  }
  })

我正在调用下表,但我收到错误 Uncaught SyntaxError: Unexpected token ILLEGAL where itemTpl is。

             {
              xtype:'list',
              store:'Details',
                itemTpl:'<img src="{icon}"></img><h1>{name:ellipsis(25)}</h1>
                <h3>{vicinity:ellipsis(35)}</h3><h2>{website}</2><h2>{reviews}</h2><tpl   for="aspects">
               {rating} - {type}
              </tpl>',
            itemCls:'place-entry'
           }

笔记:

我尝试了以下方法。错误已停止并显示所有其他信息,但方面仍然没有显示。

      itemTpl:new Ext.XTemplate(
        '<div>',
            '<div><img src="{icon}"></img><br>',
            '<h1>{name}</1><br>',
           ' </div>',
           '<div><h3>{vicinity:ellipsis(60)}</h3><h3>{website}</3><br>',
            '<h3>{formatted_phone_number}</h3><br>',
            '<tpl for="aspects"<td>{type}</td></tpl><br>',
           ' </div>',
        '</div>'
        ),

这就是模型现在的样子:

  fields: [
 {

  name: 'reviews'

 },
 {

name: 'aspects',
mapping: 'reviews.aspects'
},

{
name: 'vicinity'
},
{
name: 'name'
 },
 {
name: 'icon'
},
{
name: 'website'
 },
 {
name: 'formatted_phone_number'}]

}

样本数据:

      "reviews" : [
        {
        "aspects" : [
           {
              "rating" : 3,
              "type" : "food"
           },
           {
              "rating" : 3,
              "type" : "decor"
           },
           {
              "rating" : 3,
              "type" : "service"
           }
        ],
        "author_name" : "Aubrey Skelly",
        "author_url" : "https://plus.google.com/101776084849290882399",
        "text" : "Small and wonderful, the food fantastic, service 100% miss this    wonderful restaurant and you will miss a gem in waterford",
        "time" : 1359588944
     },
4

1 回答 1

0

我认为您必须在模型中进行映射:

fields: [
{
    name: 'aspects',
    mapping: 'reviews.aspects'
},
{
    name: 'vicinity'
}
...

然后在 tpl 中:

<tpl for="aspects">
    {rating} - {type}
</tpl>

笔记:

tpl 中不能有换行符:

//this will throw an error
itemTpl: '<div>this is some content<br>
         this is the same div but I am on a new line now</div>'

您必须拆分行:

//this is OK
itemTpl: '<div>this is some content<br>',
         'this is the same div but I am on a new line now</div>'       
于 2013-03-27T15:25:23.217 回答