【问题标题】:OrderBy math column in AngularJSAngularJS 中的 OrderBy 数学列
【发布时间】:2015-07-28 05:00:35
【问题描述】:

我有一张这样的桌子:

<tr ng-repeat="x in data | orderBy:xxxx"> <td>{{ x.name}}</td> <td>{{ x.price * x.count }}</td> </tr>

如何按 {{ x.price * x.count }} 列排序此表行。

感谢您的帮助。

【问题讨论】:

    标签: angularjs html angularjs-orderby


    【解决方案1】:

    orderBy cab 不仅接受一个值,还接受一个函数。为了在您的情况下使用它,请在您的范围内添加一个函数:

    $scope.calculateOrder = function(item) {
        return item.price * item.count;
    };
    

    然后你就可以在你的过滤器中使用这个函数了:

    <tr ng-repeat="x in data | orderBy:calculateOrder">
    

    你可以阅读更多关于orderBy on Angular documentation

    【讨论】:

      【解决方案2】:

      您可以进行内联计算。

      orderBy: 'price * count'
      

      Fiddle

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-26
        • 2014-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-12
        相关资源
        最近更新 更多