如何打印角JSON的主键值? [英] How to print main key value of JSON in Angular?
本文介绍了如何打印角JSON的主键值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我使用的类似风格的数组。我需要打印的产品名称(即产品1名,产品2名,产品3名)。如何做到这一点。
{
产品1名:[{
价格:20,
颜色:红色
}],
产品2名:[{
价格:30,
颜色:绿色
}],
产品3名:[{
价格:40,
颜色:蓝
}]
}
解决方案
假设 $ scope.products = {'产品1名:[{价:'20',颜色:红色}] 产品2名:[{价格:30,颜色:绿色}],产品3名:[{价:'40',颜色:'蓝'}]}
-
您认为应该是这样的:
< DIV NG重复=(键,VAL)的产品> {{关键}}< / DIV>
Below is the similar styled array which I'm using. I need to print that Product names (i.e. Product1 name, Product2 name, Product3 name). How to achieve that
{
'Product1 name':[{
price: '20',
color:'red'
}],
'Product2 name':[{
price: '30',
color:'green'
}],
'Product3 name':[{
price: '40',
color:'blue'
}]
}
解决方案
Assuming $scope.products = { 'Product1 name':[{ price: '20', color:'red' }], 'Product2 name':[{ price: '30', color:'green' }], 'Product3 name':[{ price: '40', color:'blue' }] }
-
Your view should be like this:
<div ng-repeat="(key,val) in products">{{ key }}</div>
这篇关于如何打印角JSON的主键值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文