Arrays 如何使用ng repeat访问angular js中的键值?
我试图在angular js中使用ng repeat显示json文件中的值,但我无法做到这一点 这是我正在尝试的代码:Arrays 如何使用ng repeat访问angular js中的键值?,arrays,json,angularjs-ng-repeat,Arrays,Json,Angularjs Ng Repeat,我试图在angular js中使用ng repeat显示json文件中的值,但我无法做到这一点 这是我正在尝试的代码: <div ng-repeat = "x in myWelcome.definition"> {{x.attributes[0].children[0].node_id}} <hr> </div> 正在工作如何使用ng repeat在视图中显示此项我需要使用ng repeat显示所有属性和子项。ng re
<div ng-repeat = "x in myWelcome.definition">
{{x.attributes[0].children[0].node_id}}
<hr>
</div>
正在工作如何使用ng repeat在视图中显示此项我需要使用ng repeat显示所有属性和子项。ng repeat可按以下方式使用:
<div ng-repeat = "(key,value) in myWelcome.definition.attributes">
Key:{{key}} and value :{{value}}
<hr>
</div>
键:{{Key}}和值:{{value}
或者您可以尝试以下方法:
<div ng-repeat = "x in myWelcome.definition.attributes">
<div ng-repeat="a in x.children">
a:{{a.node_id}}
</div>
</div>
a:{a.node_id}
ng repeat可通过以下方式使用:
<div ng-repeat = "(key,value) in myWelcome.definition.attributes">
Key:{{key}} and value :{{value}}
<hr>
</div>
键:{{Key}}和值:{{value}
或者您可以尝试以下方法:
<div ng-repeat = "x in myWelcome.definition.attributes">
<div ng-repeat="a in x.children">
a:{{a.node_id}}
</div>
</div>
a:{a.node_id}
我可以看到您正在尝试为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 -->
{{x.rm_属性_名称}
{{$index}}
{{b.children.length}
如果数组大于1,请在此处执行魔术
克尔德
您总是可以使用{{$index}}查看索引,并且应该始终使用.length检查其值是否超过1。通过这种方式,您可以实现您想要的,您还应该了解javascript中的数组以及点和括号之间的区别。请看这个。我认为您应该学习javascript的基础知识。我可以看到您正在尝试为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 -->
{{x.rm_属性_名称}
{{$index}}
{{b.children.length}
如果数组大于1,请在此处执行魔术
克尔德
您总是可以使用{{$index}}查看索引,并且应该始终使用.length检查其值是否超过1。通过这种方式,您可以实现您想要的,您还应该了解javascript中的数组以及点和括号之间的区别。请看这个。我认为你应该学习javascript的基础知识。你是说<代码>(key.x)在myWelcome.definition中键和值我知道我可以只用ng来做吗重复这里是定义我有孩子等等on@Codingisgreat,检查这个,我希望它能起作用@RohitJindal你能再看看这个问题吗?你是说<代码>(key.x)在myWelcome.definition中键和值我知道我可以只用ng来做吗重复这里是定义我有孩子等等on@Codingisgreat,检查这个,我希望它能起作用@RohitJindal你能再看一次这个问题吗?我怎么能迭代值,比如:@Codingisgreat,请检查我答案中的plunker。它将帮助您:)您也可以参考文档。我如何在值中进行迭代,例如:@Codingisgreat请检查我答案中的plunker。它将帮助您:)您也可以参考该文档