【问题标题】:AngularJS-Filters no filter empty attributeAngularJS-Filters 没有过滤器空属性
【发布时间】:2015-08-08 06:07:39
【问题描述】:

当对象的属性不存在并且我无法使用"!null" 进行过滤时,我遇到了问题,我想知道过滤器是否可以验证这一点,或者我需要为此创建一个新的过滤器。

HTMLng-repeat

 <li ng-repeat="detail in details | filter:{shortDescription: '!null'}">
    <p>{{detail.name}}</p>
 </li>

JavaScriptArray

$scope.details = [{
        name: 'Bill',
        shortDescription: null
    },{
        name: 'Bill2',
    }, {
        name: 'Sally',
        shortDescription: 'A girl'
    }];

结果

  • Bill2
  • 莎莉

Bill2 不存在 shortDescription 但没有过滤器。

预期结果:

  • 莎莉

JSFiddle http://jsfiddle.net/4wxs67yv/28/

AngularJS v.1.3.15

我该怎么做?

【问题讨论】:

标签: angularjs


【解决方案1】:

您可以尝试使用双非运算符,as

<li ng-repeat="detail in details | filter:{shortDescription: '!!'}">
<p>{{detail.name}}</p>

【讨论】:

  • 你能用答案jsfiddle.net/4wxs67yv/30 更新小提琴吗?它在这里不起作用
  • 我想要过滤,但没有存在属性时:result = *Sally
猜你喜欢
  • 2015-12-06
  • 1970-01-01
  • 1970-01-01
  • 2017-10-11
  • 1970-01-01
  • 2017-02-21
  • 1970-01-01
  • 1970-01-01
  • 2023-03-31
相关资源
最近更新 更多