0

<div class="item" data-ng-repeat="course in courses | filter:filterCourses | orderBy:predicate">...

$scope.predicate = function(course) {
    //$scope.orderProp
};

我需要在谓词中放入什么代码以便我可以

  1. 以与默认 orderBy:predicate 相同的方式排序(不确定这是否有意义)
  2. 将空 course.StartDate 放在列表的末尾

笔记:

  • course 是一个具有不同属性的对象,如标题、开始日期、代码
  • $scope.orderProp 包含排序依据的值:title、startDate、code。当 startDate 为空时,我想将这些项目放在列表的末尾,但仍然按日期正确排序,开始日期是一个“整数”,我稍后会以更好的形式显示 ng-date

谢谢

答案: 这是我最终得到的 http://jsfiddle.net/3hz2j8j7/

4

2 回答 2

2

OrderBy can accept a list of predicates (a bit like saying "order by A, then B"). So your first predicate will ensure that blank start dates go at the end, and your second one will use the value of orderProp:

<div ... orderBy:[nonEmptyStartDate, orderProp]">

$scope.nonEmptyStartDate = function(course) {
    return course.startDate=="" ? 1 : 0;
}
于 2014-09-10T23:06:08.277 回答
1

除了康斯坦丁诺斯的回答之外,我还用你的确切数据为你做了一个jsfiddle 。所有的 Angular 魔法都在

<div ng-repeat="course in courses|orderBy:[nonEmptyStartDate,orderProp]:true">

其中 orderProp='title' 以便第一个数据首先按非空日期排序,然后按标题排序。请告诉我们 。

于 2014-09-11T07:26:05.377 回答