我的问题与orderBy multiple fields in Angular不一样.
我的数组有对象,有些对象有
{
estimatedStartDate : "..."
}
有些人有:
{
actualStartDate : "..."
}
那么有没有办法同时考虑这两个字段来orderBy。
orderBy:['estimatedStartDate','actualStartDate']
^ 这行不通。
这是一个 fiddle :http://jsfiddle.net/g201tudg/1/
那么假设这两个字段相同然后排序?
最佳答案
将这样的函数添加到您的 Controller :
$scope.sortByEitherDate = function(row) {
if (row.actualStartDate) {
return row.actualStartDate;
}
return row.estimatedStartDate;
}
然后用 orderBy:sortByEitherDate 按它排序
工作 fiddle :http://jsfiddle.net/g201tudg/4/
关于javascript - Angular ng-repeat orderBy 多个字段作为一个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37280927/