在ngRepeat中对哈希对象的值进行排序 – angularJS

前端之家收集整理的这篇文章主要介绍了在ngRepeat中对哈希对象的值进行排序 – angularJS前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个像这样的对象:
$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’

你需要你的手机对象是一个真正的阵列.

尝试:

$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>
原文链接:https://www.f2er.com/angularjs/142453.html

猜你在找的Angularjs相关文章