在客户端,我有一个json对象,它是从REST服务中接收到的。这个对象有多个属性,其中一个是字符串数组。我需要一些关于如何使用嵌入在html中的角JS代码打印这个数组的帮助。这是我的JSON对象:
[
"title": "Developing a System for Information Management in Disaster Relief",
"url": "http://scholar.google.com/scholar",
"relatedTitles":
[
"Distributed robotic sensor networks",
"Improving information access for emergency",
"Tangible and wearable user interfaces for",
"Non-parametric inferenc",
"Airborne near-real-time monitoring of assembly"
]
]这是html的ng-重复的样子。
<tr ng-repeat="publication in publications">
<td>{{publication.title}}</td>
<td>{{publication.url}}</td>
<td>{{publication.relatedTitles}} </tr>注意:“发布”是JSON对象名
发布于 2014-08-06 14:55:50
这取决于你想如何打印它。如果您希望它像和数组一样,用逗号连接--例如,使用以下html代码:
<tr ng-repeat="publication in publications">
<td>{{publication.title}}</td>
<td>{{publication.url}}</td>
<td>{{publication.relatedTitles.join(', ')}}
</tr>另外,如果您想要每个<span>标记,您可以执行另一个ng-重复:
<tr ng-repeat="publication in publications">
<td>{{publication.title}}</td>
<td>{{publication.url}}</td>
<td>
<span ng-repeat="relatedTitle in publication.relatedTitles">
{{publication.relatedTitles}}
</span>
</td>
</tr>发布于 2014-08-06 14:53:41
你可以筑巢ng-repeat's
所以你应该能做这样的事情:
<tr ng-repeat="publication in publications">
<td>{{publication.title}}</td>
<td>{{publication.url}}</td>
<td>
<table>
<tr ng-repeat="title in publication.relatedTitles">
<td>{{title}}</td>
</tr>
</table>
</td>
</tr>发布于 2014-08-06 14:55:51
<tr ng-repeat="publication in publications">
<td>{{publication.title}}</td>
<td>{{publication.url}}</td>
<td>
<span ng-repeat="title in publication.relatedTitles">
{{title}}<br>
</span>
</td>
</tr>https://stackoverflow.com/questions/25163533
复制相似问题