我迷失了为什么orderBy不工作,ng-repeat输出的顺序无论我传递给orderBy的属性是什么,例如orderBy:' - year1comp'或orderBy:'year1comp'没有效果。
$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>
答案 0 :(得分:3)
您需要在orderBy之后移动跟踪:
<div class="multiple-repeat-container" ng-repeat="item in expTest | orderBy:'-year1comp' track by $index "> ... </div>
请注意,跟踪表达式必须位于任何过滤器和别名表达式之后。