AngularJs的order过滤器不支持跟踪



我对orderderby不工作的原因感到困惑,无论我传递给orderderby的属性是什么,例如orderderby:'-year1comp'或orderderby:'year1comp'都没有影响,ng-repeat输出的顺序都是相同的。

$scope.expTest = [{
    "company": "new",
    "schedule": "fulltime",
    "titlecomp": "c",
    "status": "temporary",
    "locationcomp": "fdsf",
    "category": "114",
    "month1comp": 4,
    "year1comp": 2004,
    "month2comp": 5,
    "year2comp": 1997,
    "desccomp": "dafds",
    "companydesc": "fdsaf",
    "_id": 0
}, {
    "company": "new",
    "schedule": "fulltime",
    "titlecomp": "b",
    "status": "temporary",
    "locationcomp": "fdsf",
    "category": "114",
    "month1comp": 4,
    "year1comp": 2015,
    "month2comp": 2,
    "year2comp": 2010,
    "desccomp": "dafds",
    "companydesc": "fdsaf",
    "_id": 1
}, {
    "company": "company name",
    "schedule": "fulltime",
    "titlecomp": "a",
    "status": "contract",
    "locationcomp": "sfdg",
    "category": "114",
    "month1comp": 2,
    "year1comp": 2015,
    "desccomp": "fdgsfdg",
    "companydesc": "fdgfdg",
    "_id":2
}]
模板的HTML

<div class="multiple-repeat-container" 
ng-repeat="item in expTest track by $index | orderBy:'-year1comp' "> ... </div>

您需要将跟踪移动到order:

<div class="multiple-repeat-container" ng-repeat="item in expTest | orderBy:'-year1comp' track by $index "> ... </div>

文档说明

注意,跟踪表达式必须在任何过滤器和别名表达式之后。

最新更新