AngularJs orderBy 过滤器不适用于跟踪
AngularJs orderBy filter not working with tracking
我不知道为什么 orderBy 不起作用,无论我传递给 orderBy 什么,ng-repeat 输出的顺序都是相同的 属性 例如 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>
您需要在orderBy之后移动跟踪:
<div class="multiple-repeat-container" ng-repeat="item in expTest | orderBy:'-year1comp' track by $index "> ... </div>
Note that the tracking expression must come last, after any filters, and the alias expression.
我不知道为什么 orderBy 不起作用,无论我传递给 orderBy 什么,ng-repeat 输出的顺序都是相同的 属性 例如 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>
您需要在orderBy之后移动跟踪:
<div class="multiple-repeat-container" ng-repeat="item in expTest | orderBy:'-year1comp' track by $index "> ... </div>
Note that the tracking expression must come last, after any filters, and the alias expression.