【发布时间】:2014-08-05 20:17:44
【问题描述】:
我有一个要在网格中显示的邮件列表 (<table>)。其中一些邮件带有附件。对于它们对应的行,我想在附件列中显示一个附件图标。休息时,它应该是空的。
JsFiddle:http://jsfiddle.net/6s4Z5/
我的模板如下:
<table id="resultTable">
<thead>
<tr>
<th ng-repeat="columnId in schema.columnOrder">
<img src="icon_attach.png" ng-if="columnId == 'hasAttachments'">
{{schema.columns[columnId].displayText}}
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in results.mails">
<td ng-repeat="columnId in schema.columnOrder">
<img src="icon_attach.png" ng-if="columnId == 'hasAttachments' && row.hasAttachments">
<span ng-if="columnId != 'hasAttachments'" >{{ row[columnId] }}</span>
</td>
</tr>
</tbody>
</table>
其中schema.columnOrder 是要在表中显示的 columnId 数组。
此模板有效,但这是实现此模板的最佳方式吗?此外,我必须为ng-if 语句添加额外的<span>。也可以去掉吗?
【问题讨论】:
标签: angularjs angularjs-ng-repeat angular-ng-if