我正在使用orderBy订购下拉列表,但它无效。有人可以就此提出建议吗?如果您需要任何其他信息,请告诉我。
<select class="selectbox form-control" class="form-control" data-ng-model="ctrl.task.delegateFromId" data-ng-options="user.marsId as user.fullName for user in ctrl.userList | orderBy:'fullName' ">
<option value="">-- Select Area Owner --</option>
</select>
here is plunker for this question 1st drop down order by is working but for 2nd it is not working
答案 0 :(得分:1)
我不知道你的问题是什么,但我举了一个简单的例子。
var myapp = angular.module('myapp', []);
myapp.controller('Ctrl', function ($scope) {
var vm = this;
vm.userList =JSON.parse('{"11":{"marsId":"11","firstName":"cc","lastName":"cc","fullName":"cc cc"},"12":{"marsId":"12","firstName":"aa","lastName":"aa","fullName":"aa aa"},"45":{"marsId":"45","firstName":"kk","lastName":"kk","fullName":"kk kk"}}');
vm.userList2 = [];
for (var key in vm.userList) {
var tempObj = "";
tempObj = vm.userList[key];
vm.userList2.push(tempObj);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myapp" ng-controller="Ctrl as vm">
<select class="selectbox form-control" class="form-control" data-ng-model="vm.task.delegateFromId" data-ng-options="user.marsId as user.fullName for user in vm.userList2 | orderBy:'fullName' ">
<option value="">-- Select Area Owner --</option>
</select>
</div>
答案 1 :(得分:0)
亲爱的,如果您希望按字母顺序对名称进行排序,请尝试以下操作:
<select class="selectbox form-control" class="form-control" data-ng-model="ctrl.task.delegateFromId" data-ng-options="user.marsId as user.fullName for user in ctrl.userList | orderBy:'toString()' ">
<option value="">-- Select Area Owner --</option>
</select>
谢谢&amp;干杯强>