2

orderBy 函数被完全忽略。我在某一时刻添加了一个 console.log 进行测试,甚至没有调用该函数。数据仍然显示,但无序。

HTML 代码

<div id="tabs">
    <a ng-repeat="tab in tabs | orderBy:tabordinal" id="tab-{{tab.tab_id}}" class="{{getClasses(tab)}}" ng-click="tabclick(tab)">{{tab.label}}</a>
</div>

JS函数

$scope.tabordinal = function (tab) {
    return $scope.taborder.indexOf(tab.tab_id);
};

其他一切都设置正确,(即 ng-click 正常工作,数据正确绑定,过滤器正在处理其他元素。

4

1 回答 1

4

A few things...

  1. orderBy takes a string, or an expression that returns a string. That string should be the name of a property you want to order by on the list of objects you're ordering. So if the objects in your array have properties like [ { 0: 'foo', 1: 'bar', '2': 'blah' } ], then you're good to go, I guess. But I doubt they're structured like that.
  2. orderBy:tabOrdinal() if your expression is a function, as yours is in the original post, you need that ().

Outside of that, if you provide a fiddle, I can give you more help.

于 2012-12-05T17:34:49.240 回答