本文介绍了在ngRepeat散列对象的排序值 - angularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个对象:

  $ scope.phones =新的对象();
$ scope.phones ['ID1'] = {
    名:手机名1
    dateReleased:2012年1月9日15点48分24秒
};
$ scope.phones ['id2的'] = {
    名:手机名称2
    dateReleased:2012-3-12 15点32分11秒
};
$ scope.phones ['ID3'] = {
    名:电话NAME3
    dateReleased:2012-2-10 13时53分32秒
};

我这显示使用ngRepeat。我不能够通过 dateReleased 订购。此外,订货没有作相反的工作。我ngRepeat看起来这样的:

 <李NG重复=手机电话|排序依据:dateReleased:真正的>
    &所述p为H.; {{phone.name}}&下; / P>
    &所述p为H.; {{phone.dateReleased}}&下; / P>
< /李>


解决方案

如果您查看它说,在排序依据除权pression可以是一个的功能,一个字符串阵列。因此,一个你需要的 dateReleased 是一个字符串:dateReleased

另外你需要你的电话对象的实际阵列。

尝试:

  $ scope.phones = {[
        名:手机名1
        dateReleased:2012年1月9日15点48分24秒
    },{
        名:手机名称2
        dateReleased:2012-3-12 15点32分11秒
    },{
        名:电话NAME3
        dateReleased:2012-2-10 13时53分32秒
    }];<李NG重复=手机电话|排序依据:'dateReleased:真正的>
    &所述p为H.; {{phone.name}}&下; / P>
    &所述p为H.; {{phone.dateReleased}}&下; / P>
< /李>

I have an object like this:

$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"
};

I'm displaying this using ngRepeat. I'm not able to order by dateReleased. Also, ordering in reverse isn't working. My ngRepeat looks this:

<li ng-repeat="phone in phones | orderBy:dateReleased:true">
    <p>{{phone.name}}</p>
    <p>{{phone.dateReleased}}</p>
</li>
解决方案

If you check the documentation it says that the expression in orderBy can be a function, a string or an Array. An therefore you need dateReleased to be a string: 'dateReleased'

Also you need your phones Object be an actual Array.

Try:

$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>

这篇关于在ngRepeat散列对象的排序值 - angularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 00:06