gpt4 book ai didi

object - 在ng Repeat中对哈希对象的值进行排序-angularJS

转载 作者:行者123 更新时间:2023-12-04 04:59:55 25 4
gpt4 key购买 nike

我有一个这样的对象:

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

关于object - 在ng Repeat中对哈希对象的值进行排序-angularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13552387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com