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 whereitemTplisを取得しています。

             {
              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 に答える