我试图在我的模型中引用复杂的 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
},