我有一点问题..我的项目有属性,每个属性都像 关键和价值。
我需要在我的页面中放置属性键desctiption的值..但我不知道它是怎么做的。
这是我的json数据
[
{
"id": 2323,
"name": "small ring",
"attributes": [
{
"key": "weight",
"value": "90"
},
{
"key": "description",
"value": "A little ring"
}
]
},
{
"id": 2324,
"name": "big ring",
"attributes": [
{
"key": "weight",
"value": "90"
},
{
"key": "description",
"value": "A Big ring"
}
]
}]
这是我的HTML主体。
<div class="list-group ">
<a href="#" ng-repeat="item in items " class="list-group-item clearfix">
<span style="padding-left:5px;padding-right:5px;" class="pull-left">
{{item.name}}
<p><small>{{item.attribute}} </small></p><!-- Here -->
</span>
</a>
</div>
答案 0 :(得分:1)
快速解决方案:
<div class="list-group ">
<a href="#" ng-repeat="item in items " class="list-group-item clearfix">
<span style="padding-left:5px;padding-right:5px;" class="pull-left">
{{item.name}}
<p><small>
<span ng-repeat="attr in item.attributes" ng-if="attr.key == 'description'">{{ attr.value }}</span>
</small></p>
</span>
</a>
</div>
这应该有效。它循环遍历属性,但只有在其键等于description
时才显示该属性。