【问题标题】:How can I make orderBy refresh on every change如何在每次更改时刷新 orderBy
【发布时间】:2017-04-21 16:31:31
【问题描述】:

我有一个检查值是真还是假的函数和一个改变值的函数。

checkValue(item){  
    if item.exists{  
        return 1;  
    }  
    else {  
        return 0;  
    }  
} 

在我的 html 中,我有一个 ng-repeat,它通过这个函数订购:

<span ng-repeat="item in items | orderBy: checkValue"></span>
<a ng-click="changeItemExists(selectedItem)">

现在当item.exists 更改orderBy 不再起作用并再次订购跨度。

如何通过 orderBy 来查看 item.exsist 中的任何变化?

【问题讨论】:

  • 在您的 changeItemExists() 函数中添加 $scope.checkValueitem = selectedItem;。并将checkValue(item) 更改为checkValue(){var item = $scope.checkValueItem; }
  • 请不要在你的问题上加上不相关的标签,这个问题与 Angular 无关。它只是 AngularJS。

标签: angularjs angularjs-ng-repeat angularjs-orderby


【解决方案1】:

您不需要checkValue 函数。 就这样吧:

<span ng-repeat="item in items | orderBy: 'exists'"></span>

然后orderBy 将根据“存在”属性的任何更改自动刷新订单。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    相关资源
    最近更新 更多