如何打印字符串数组,这是JSON的一部分,由其他属性组成
How to print a string array which is part of a JSON consists of other attributes
在客户端,我有一个json对象,我从某处的REST服务接收。这个对象有不止一个属性,其中一个是字符串数组。我想要一些关于如何使用嵌入在html中的angular 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-repeat的样子。
<tr ng-repeat="publication in publications">
<td>{{publication.title}}</td>
<td>{{publication.url}}</td>
<td>{{publication.relatedTitles}} </tr>
注意:"publications"是JSON对象的名称
这取决于你想如何打印它。如果你想让它像数组一样,例如用逗号连接,使用以下html代码:
<tr ng-repeat="publication in publications">
<td>{{publication.title}}</td>
<td>{{publication.url}}</td>
<td>{{publication.relatedTitles.join(', ')}}
</tr>
否则,如果您想使用每个<span>
标记,例如,您可以执行另一个ng-repeat:
<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>
可以嵌套ng-repeat
所以你应该可以这样做:
<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>
<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>
相关文章:
- 如何添加浮动和非浮动,其他
- 与其他库的jQuery.noConflict()
- 播放当前视频时如何停止其他视频?JavaScript
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- 制作一个不带HTML a标记但在动画播放完毕后指向其他页面的超链接
- 除修剪外的其他功能
- 是什么让一个“;Uncaught RangeError:超过了最大调用堆栈大小“;错误(Chrome,在其他浏览器中显示
- Array.length似乎不起作用;console.log则显示其他情况
- 如何消除代码中的未定义和其他问题
- 如何覆盖锚点元素's href目标,并在我点击转到目标javascript时删除其他错误
- 将 json 数组的一部分分别排序到同一数组的其他部分
- 删除在单击其他选项卡时生成的url查询元素的一部分
- 当鼠标悬停在页面的其他部分上时,如何滚动页面的一部分
- 如何打印字符串数组,这是JSON的一部分,由其他属性组成
- 如何阻止用户点击任何其他按钮,而页面刷新(从模态窗口解决方案的一部分)
- 从javascript中获取其他字段的值,javascript是select标记html的一部分
- 如何在单击相应菜单项时显示/隐藏一部分内容,同时隐藏所有其他内容
- 如何只删除我的域设置的cookie的一部分(为其他应用程序设置的其他几个cookie)
- 如何在我的网站显示其他网站的一部分