admin管理员组文章数量:1386647
Below is my JSON object which I would like to display the name in both the parent and child array.
$scope.result= [
{
"id": 1,
"name": "1002",
"parentArray": [
{
"id": 28,
"name": "PRODP1",
"shortCode": "PRODP1"
}
]
}
I want to display Name:1002 Parent_Name:PRODP1
I tried {{item.name}} which will only display 1002.But I need to display the name of parentArray as well.
Below is my JSON object which I would like to display the name in both the parent and child array.
$scope.result= [
{
"id": 1,
"name": "1002",
"parentArray": [
{
"id": 28,
"name": "PRODP1",
"shortCode": "PRODP1"
}
]
}
I want to display Name:1002 Parent_Name:PRODP1
I tried {{item.name}} which will only display 1002.But I need to display the name of parentArray as well.
Share Improve this question asked Apr 22, 2015 at 7:48 forgottoflyforgottofly 2,72912 gold badges54 silver badges97 bronze badges 3-
{{ item.parentArray[0].name }}
? – fracz Commented Apr 22, 2015 at 7:49 - @fracz When there are more than one parentArray? – forgottofly Commented Apr 22, 2015 at 7:51
- how do you want to handle if more than one parent arrays.. update your question with sample example of how should that case be displayed – harishr Commented Apr 22, 2015 at 7:57
2 Answers
Reset to default 5Since the parentArray is also an array your going to need a nested ng-repeat
.
If this is a large page then this may cause a performance issue.
<div ng-repeat="item in result">
{{item.name}}
<div ng-repeat="innerItem in item.parentArray">
{{innerItem.name}}
</div>
</div>
parentArray
is an...array, so you need to access it using an index:
<div ng-repeat="item in result">
Name: {{ item.name }} Parent_Name: {{ item.parentArray.length ? item.parentArray[0].name : '' }}
</div>
That's under the assumption that there is one object in parentArray
. You might need to iterate it, or you might need to check to see if it exists depending on your requirements.
本文标签: javascriptDisplay an Array inside Object using ngrepeat AngularJsStack Overflow
版权声明:本文标题:javascript - Display an Array inside Object using ng-repeat -AngularJs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744504073a2609487.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论