我有一个像这样的对象:
$scope.phones = new Object(); $scope.phones['id1'] = { "name":"Phone Name1","dateReleased":"2012-1-09 15:48:24" }; $scope.phones['id2'] = { "name": "Phone Name2","dateReleased":"2012-3-12 15:32:11" }; $scope.phones['id3'] = { "name": "Phone Name3","dateReleased":"2012-2-10 13:53:32" };
我正在使用ngRepeat显示它.我无法通过dateReleased订购.此外,反向排序不起作用.我的ngRepeat看起来像这样:
<li ng-repeat="phone in phones | orderBy:dateReleased:true"> <p>{{phone.name}}</p> <p>{{phone.dateReleased}}</p> </li>
如果检查
documentation,则表示orderBy中的表达式可以是函数,字符串或数组.因此,您需要dateReleased为字符串:’dateReleased’
原文链接:https://www.f2er.com/angularjs/142453.html你需要你的手机对象是一个真正的阵列.
尝试:
$scope.phones = [{ "name":"Phone Name1","dateReleased":"2012-1-09 15:48:24" },{ "name": "Phone Name2","dateReleased":"2012-3-12 15:32:11" },{ "name": "Phone Name3","dateReleased":"2012-2-10 13:53:32" }]; <li ng-repeat="phone in phones | orderBy:'dateReleased':true"> <p>{{phone.name}}</p> <p>{{phone.dateReleased}}</p> </li>