【发布时间】:2015-06-05 18:07:46
【问题描述】:
如何按子属性"active" : true 对项目列表进行排序?第一个节点是为每个朋友动态插入的 id。
<li data-ng-repeat="friend in friends|orderBy:'friend.active':true">
<span class="name">{{friend.name}}</span>
<span class="phone">{{friend.lastName}}</span>
</li>
$scope.friends = {
"12345": {
"name": "Dhiraj",
"lastName": "Agarwal",
"active" : false
},
"23456": {
"name": "Poonam",
"lastName": "Mittal",
"active" : false
},
"34567": {
"name": "Suresh",
"lastName": "Bansal",
"active" : true
},
"45678": {
"name": "Usha",
"lastName": "Goel",
"active" : false
}
};
【问题讨论】:
-
代替
friend.active,你能试试"friend in friends | orderBy: 'active': true"吗? -
orderBy 用于数组,而不是对象。
标签: angularjs angularjs-ng-repeat ng-repeat angularjs-orderby