我试图在我的视图中迭代JSON数组,但我只想显示具有非空字符串值的键。
design:
{name: "ux", value: "3", $$hashKey: "object:5198"}
{name: "graphic", value: "", $$hashKey: "object:5199"}
{name: "concept", value: "4", $$hashKey: "object:5200"}
{name: "photoshop", value: "", $$hashKey: "object:5201"}
{name: "illustrator", value: "5", $$hashKey: "object:5202"}
{name: "inDesign", value: ""}
{name: "afterEffects", value: ""}
{name: "premierePro", value: "1"}
如何在迭代数组时只获取数组的键,只显示具有实际值的数组。
我目前的代码是:
<div class="six columns">
<div ng-repeat="skill in employeeDetails.design | limitTo:5:0 | filter:{value:'! '}">
{{ skill.name | capitalize }} {{ skill.value }}
</div>
</div>
任何帮助都将受到高度赞赏!
答案 0 :(得分:1)
在这种情况下,您可以使用ng-if
:
<div class="six columns">
<div ng-repeat="skill in employeeDetails.design | limitTo:5:0" ng-if="skill.value !== '' ">
{{ skill.name | capitalize }} {{ skill.value }}
</div>
</div>
或更改您的filter
<div class="six columns">
<div ng-repeat="skill in employeeDetails.design | limitTo:5:0 | filter:{value:'!! '}" ng-if="skill.value !== '' ">
{{ skill.name | capitalize }} {{ skill.value }}
</div>
</div>