I am trying to show the value from my json files using ng-repeat in angular js but I am unable to do that.
我试图在角度js中使用ng-repeat显示我的json文件的值,但我无法做到这一点。
This is my code which I am trying:
这是我正在尝试的代码:
<div ng-repeat = "x in myWelcome.definition">
{{x.attributes[0].children[0].node_id}}
<hr>
</div>
I have tried this and it is working:
我试过这个并且它正在工作:
<!-- first attributes start -->
<div ng-repeat = "x in myWelcome.definition.attributes">
{{x.rm_attribute_name}}<hr>
<div ng-repeat="a in x.children">
<div ng-if ="a.attributes">
a: {{a.attributes[0].rm_attribute_name}}
<div ng-if= "a.attributes[0].children">
chld
</div>
</div>
</div>
</div>
<!-- second attributes end -->
I am trying to understand how this line is working {{a.attributes[0].rm_attribute_name}} why it is not working like this {{a.attributes1.rm_attribute_name}} this is confusing. How it is shwoing all the results when I am using 0 and index. And my json file is here in the plunker: Plunker link of json and code
我试图理解这一行是如何工作的{{a.attributes [0] .rm_attribute_name}}为什么它不能像{{a.attributes1.rm_attribute_name}}这样工作这令人困惑。当我使用0和索引时,它是如何影响所有结果的。我的json文件在plunker中:json和code的Plunker链接
So how can I iterate here using ng-repeat here this code:
那么我怎么能在这里使用ng-repeat迭代这里代码:
{{myWelcome.definition.attributes[0]}}
is working how can I show this in my view using ng-repeat I need to show all the attributes and child using ng-repeat.
正在工作如何使用ng-repeat在我的视图中显示这个我需要使用ng-repeat显示所有属性和子项。
2 个解决方案
#1
0
I can see you are trying to implement ng-if and ng-repeat for your json file. You need to understand how ng-repeat works you can always check the index of you array using {{$index}}. So for your kind of problem I think this is the solution you should try.
我可以看到你正在尝试为你的json文件实现ng-if和ng-repeat。您需要了解ng-repeat的工作原理,您始终可以使用{{$ index}}检查数组的索引。所以对于你的问题,我认为这是你应该尝试的解决方案。
<!-- first attributes start -->
<div ng-repeat = "x in myWelcome.definition.attributes">
{{x.rm_attribute_name}}<hr>
<div ng-repeat="a in x.children">
{{$index}}
<div ng-if ="a.attributes">
<div ng-repeat="b in a.attributes">
<hr>
{{b.children.length}}
<div ng-if="b.children.length > 1">
If the array is more than 1 please do the magic here
</div>
</div>
<div ng-if= "a.attributes[0].children">
chld
</div>
</div>
</div>
</div>
<!-- second attributes end -->
You can always see the indexes using {{$index}} and you should always use .length to check if it has more than 1 value. This way you can achieve what you want and you should also learn something about arrays in javascript and what is the differnece between dot and bracket. Please read this http://www.dev-archive.net/articles/js-dot-notation/. I think you should learn the basics of javascript.
您始终可以使用{{$ index}}查看索引,并且应始终使用.length来检查它是否具有多于1的值。这样你就可以实现你想要的东西,你也应该学习javascript中的数组,以及dot和括号之间的区别。请阅读http://www.dev-archive.net/articles/js-dot-notation/。我认为你应该学习javascript的基础知识。
#2
2
ng-repeat can be used in the following way:
ng-repeat可以通过以下方式使用:
<div ng-repeat = "(key,value) in myWelcome.definition.attributes">
Key:{{key}} and value :{{value}}
<hr>
</div>
OR you can Try this:
或者你可以尝试这个:
<div ng-repeat = "x in myWelcome.definition.attributes">
<div ng-repeat="a in x.children">
a:{{a.node_id}}
</div>
</div>
编辑Plunker
#1
0
I can see you are trying to implement ng-if and ng-repeat for your json file. You need to understand how ng-repeat works you can always check the index of you array using {{$index}}. So for your kind of problem I think this is the solution you should try.
我可以看到你正在尝试为你的json文件实现ng-if和ng-repeat。您需要了解ng-repeat的工作原理,您始终可以使用{{$ index}}检查数组的索引。所以对于你的问题,我认为这是你应该尝试的解决方案。
<!-- first attributes start -->
<div ng-repeat = "x in myWelcome.definition.attributes">
{{x.rm_attribute_name}}<hr>
<div ng-repeat="a in x.children">
{{$index}}
<div ng-if ="a.attributes">
<div ng-repeat="b in a.attributes">
<hr>
{{b.children.length}}
<div ng-if="b.children.length > 1">
If the array is more than 1 please do the magic here
</div>
</div>
<div ng-if= "a.attributes[0].children">
chld
</div>
</div>
</div>
</div>
<!-- second attributes end -->
You can always see the indexes using {{$index}} and you should always use .length to check if it has more than 1 value. This way you can achieve what you want and you should also learn something about arrays in javascript and what is the differnece between dot and bracket. Please read this http://www.dev-archive.net/articles/js-dot-notation/. I think you should learn the basics of javascript.
您始终可以使用{{$ index}}查看索引,并且应始终使用.length来检查它是否具有多于1的值。这样你就可以实现你想要的东西,你也应该学习javascript中的数组,以及dot和括号之间的区别。请阅读http://www.dev-archive.net/articles/js-dot-notation/。我认为你应该学习javascript的基础知识。
#2
2
ng-repeat can be used in the following way:
ng-repeat可以通过以下方式使用:
<div ng-repeat = "(key,value) in myWelcome.definition.attributes">
Key:{{key}} and value :{{value}}
<hr>
</div>
OR you can Try this:
或者你可以尝试这个:
<div ng-repeat = "x in myWelcome.definition.attributes">
<div ng-repeat="a in x.children">
a:{{a.node_id}}
</div>
</div>
编辑Plunker