【发布时间】: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
我有一张这样的桌子:
<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
orderBy cab 不仅接受一个值,还接受一个函数。为了在您的情况下使用它,请在您的范围内添加一个函数:
$scope.calculateOrder = function(item) {
return item.price * item.count;
};
然后你就可以在你的过滤器中使用这个函数了:
<tr ng-repeat="x in data | orderBy:calculateOrder">
你可以阅读更多关于orderBy on Angular documentation
【讨论】:
【讨论】: