Angularjs 如何在ng repeat(键,值)中按值过滤,并且仅在值不为null时显示?
我有一个具有多个属性的对象,我想过滤掉空属性。大多数属性都不是必需的,可以为null。我想不出怎么做一个过滤器Angularjs 如何在ng repeat(键,值)中按值过滤,并且仅在值不为null时显示?,angularjs,key-value,ng-filter,Angularjs,Key Value,Ng Filter,我有一个具有多个属性的对象,我想过滤掉空属性。大多数属性都不是必需的,可以为null。我想不出怎么做一个过滤器 <div class="hero-unit" ng-repeat="(key, value) in selectedItem | valueNotNull"> <span class="hero-title">{{key|insertSpaces}} : </span>
<div class="hero-unit" ng-repeat="(key, value) in selectedItem | valueNotNull">
<span class="hero-title">{{key|insertSpaces}} : </span>
<span class="hero-content">{{ value }}</span>
{{key | insertSpaces}}:
{{value}}
当属性值为null或为空时,我不想显示该特定属性的英雄单位。并且仍然显示其余属性。
<div class="hero-unit" ng-repeat="(key, value) in selectedItem | filter:{value:''}">
<span class="hero-title">{{key|insertSpaces}} : </span>
<span class="hero-content">{{ value }}</span>
{{key | insertSpaces}}:
{{value}}
您应该用filter(您希望不为null的值)检查它。
{{key | insertSpaces}}:
{{value}}
您应该使用filter(您希望不为null的值)检查它。您可以隐藏空值 像这样试试
<div class="hero-unit" ng-repeat="(key, value) in selectedItem" ng-hide="!value">
<span class="hero-title">{{key|insertSpaces}} : </span>
<span class="hero-content">{{ value }}</span>
{{key | insertSpaces}}:
{{value}}
您可以隐藏空值
像这样试试
<div class="hero-unit" ng-repeat="(key, value) in selectedItem" ng-hide="!value">
<span class="hero-title">{{key|insertSpaces}} : </span>
<span class="hero-content">{{ value }}</span>
{{key | insertSpaces}}:
{{value}}
如果符合以下条件,您也可以使用ng:
<div class="hero-unit" ng-repeat="(key, value) in selectedItem | valueNotNull"
ng-if="value">
<span class="hero-title">{{key|insertSpaces}} : </span>
<span class="hero-content">{{ value }}</span>
</div>
{{key | insertSpaces}}:
{{value}}
这将隐藏
键-值对,其中值不真实(即为null、未定义等)。如果,也可以使用ng:
<div class="hero-unit" ng-repeat="(key, value) in selectedItem | valueNotNull"
ng-if="value">
<span class="hero-title">{{key|insertSpaces}} : </span>
<span class="hero-content">{{ value }}</span>
</div>
{{key | insertSpaces}}:
{{value}}
这将隐藏
键-值对,其中值不真实(即为null、未定义等)。通过将值作为参数传递来检查以外的其他条件,从而修改此选项!truthy
并解决了我的问题。通过将值作为参数传递来检查除以外的其他条件,修改了此选项!truthy解决了我的问题