Handlebars没有在Emberjs中的数组上循环
Handlebars not looping over array in Emberjs
我从服务器中检索到这个JSON对象
{
"Totals": {
"TotalNotifications": 10,
"TotalUnreadNotifications": 5
},
"NotificationData": [{
"NotificationId": 1,
"NotificationType": "Alert",
"NotificationName": "Low Battery",
"NotificationDate": "2014-09-08T19:38:57.659",
"NotificationRead": false,
"NotificationActive": true,
"AlertData": {
"AlertType": "Battery",
"AlertSeverity": "Critical"
}
}, {
"NotificationId": 2,
"NotificationType": "Dtcprimary",
"NotificationName": "Mass or Volume Air Flow",
"NotificationDate": "2014-09-01T12:00:00.000",
"NotificationRead": false,
"NotificationActive": true,
"DtcData": {
"DtcCode": "P0101",
"Vehicle": "2000 Cadillac Deville 4.6L",
"DtcDescription": "Mass or Volume Air Flow A Circuit Range Performance",
"ShortDescription": "Ceat ame aut placcat doluptus, quo berum quiandae quid quissim agnimus danimol uptae. Neque si omnis sequo torabori tem nobitatet arcit aut incimaxim fugia sitatium",
"IdentifixId": "Click <a target='"_blank'" href='"https://www.google.com'">here</a> to request a list of top fixes."
}
}, {
"NotificationId": 3,
"NotificationType": "Dtcsecondary",
"NotificationName": "Mass or Volume Air Flow",
"NotificationDate": "2014-08-01T12:00:00.000",
"NotificationRead": true,
"NotificationActive": false,
"DtcData": {
"DtcCode": "P0101",
"Vehicle": "2000 Cadillac Deville 4.6L",
"DtcDescription": "Mass or Volume Air Flow A Circuit Range Performance",
"ShortDescription": "Ceat ame aut placcat doluptus, quo berum quiandae quid quissim agnimus danimol uptae. Neque si omnis sequo torabori tem nobitatet arcit aut incimaxim fugia sitatium",
"TopReportedFix": "Replace Air Intake Boot",
"FrequentlyReportedFixes": "<ul><li>Cleaned Mass Air Flow (MAF) Sensor</li><li>Programmed Powertrain Control Module (PCM)</li></ul>",
"AlsoReportedFixes": "<ul><li>Cleaned Mass Air Flow (MAF) Sensor</li><li>Cleaned throttle body</li><li>Flushed fuel tank w/P0171, P0174</li></ul>"
}
}, {
"NotificationId": 4,
"NotificationType": "Recall",
"NotificationName": "Mass or Volume Air Flow A Circuit Range Performance",
"NotificationDate": "2014-09-01T12:00:00.000",
"NotificationRead": false,
"NotificationActive": true,
"RecallId": 31234
}]
}
当我在Notification对象上循环时,不会发生任何事情。当我尝试普通的车把时,它工作得很好,http://jsbin.com/lemafe/1/edit
以下是我在Emberjs组件中循环的方式。items
是属性传递到组件后的名称。
{{alerts-dashboard items=model}}
{{#each items}}
{{Totals.TotalUnreadNotifications}} // this outputs the number 5 as expected
{{#each NotificationData}}
{{NotificationId}} //this doesn't get outputted because the loop never happens
{{/each}}
{{/each}}
为什么它在Emberjs中不起作用?
您需要使用{{#each item in items}}
。
{{#each item in items}}
{{item.Totals.TotalUnreadNotifications}}
{{#each item.NotificationData}}
{{NotificationId}}
{{/each}}
{{/each}}
我创建了一个JSBin示例。
编辑:
这是我编辑过的JSBin,显示了如果你使用notificationData
的小写名称,它也可以工作,就像我在SO上找到的这个相关答案中提到的那样
{{#each model}}
<li>{{Totals.TotalUnreadNotifications}}</li>
<ul>
{{#each notificationData}}
<li>Type: {{NotificationType}}</li>
{{/each}}
</ul>
{{/each}}
相关文章:
- javascript:数组循环
- 如何将数组循环到JSON代码中
- 而与数组循环
- JavaScript 数组/循环不起作用
- AJAX在数组循环中调用,只在上一次完成后调用next
- 数组循环以获取单个值
- JavaScript数组循环
- Javascript 2D数组循环停止
- 通过Javascript中的JSON数组循环
- 为什么以下 forEach 数组循环未返回未定义
- 如何在数组循环中过滤数据
- 如何在数组循环 222 中过滤数据
- 数组循环以确定范围平均值
- 对象的数组循环
- 对象键及其值的数组循环
- 虽然的缺点!未定义的数组循环
- 数组循环导致无限循环
- 数组循环 - 处理下拉列表中的空值
- 在 Node 中连接数组循环.js glob 结果
- JavaScript 图像数组循环