我想在网格的下一行中显示一个嵌套的JSON对象。我正在使用Ember和mdc-layout-grid。
我的JSON数据如下:
data = [{
"amzOrderId": "403-8957866-2673902",
"financialEventType": "SHIPMENT",
"timestamp": 1570025882722,
"numOfItems": 1,
"nested": [{
"amzOrderId": "405-3430902-0842748",
"financialEventType": "SHIPMENT",
"timestamp": 1570025882722,
"numOfItems": 1}]},
{
"amzOrderId": "171-9021455-7043516",
"financialEventType": "SHIPMENT",
"timestamp": 15700258888722,
"numOfItems": 1,
"nested":null,
}]
要渲染的我的hbs文件:
<li class="sales-list-row">
{{#mdc-layout-grid as |grid|}}
{{#grid.inner as |inner|}}
{{#inner.cell class="bought" span=2}}
<h3 class="bought__value">{{get data "numOfItems"}}</h3>
{{/inner.cell}}
{{#inner.cell class="purchased" span=2}}
<span class="purchased__text">Purchased</span>
<h3 class="purchased__value">{{format-date (get data "timestamp") "date"}}</h3>
{{/inner.cell}}
{{#inner.cell class="id" span=2}}
<h4 class="id__value">{{get data "amzOrderId"}}</h4>
{{/inner.cell}}
{{/grid.inner}}
{{/mdc-layout-grid}}
</li>
现在,如果存在,我想在下一行中呈现“嵌套的”对象值(如果嵌套为null,则移至下一个data [element])。我该如何解决这个问题?我尝试了几种方法,但是它们不起作用。
我希望答案能帮助任何人。我很容易在上述HBS文件的末尾添加了此循环:
{{#if data.nested}}
{{#each data.nested as |row|}}
{{nested-row data1=row}}
{{/each}}
{{/if}}
并且组件nested-row.hbs将具有与上面的HBS文件相同的代码,但是我们需要使用get data1。希望能帮助到你!!