<div custom-select name="pSelect" id="pSelect" ng-model="selectedP" ng-trim="false" ng-options="p as p.name for p in data"></div>
这是我的自定义下拉列表。数据来自json对象。
答案 0 :(得分:1)
<div custom-select name="pSelect" id="pSelect" ng-model="selectedP" ng-trim="false" ng-options="p as p.name for p in data | orderBy:'name'"></div>
你在寻找类似的东西吗?
答案 1 :(得分:0)
尝试使用有角度的orderby,上面会看起来像这样。
//last attribute of orderBy would depend on ascending or descending.
<div custom-select name="pSelect" id="pSelect" ng-model="selectedP" ng-trim="false" ng-options="p as p.name for p in data | orderBy: 'p': true"></div>
//or set dynamically
<div custom-select name="pSelect" id="pSelect" ng-model="selectedP" ng-trim="false" ng-options="p as p.name for p in data | orderBy: type : true"></div>
<button ng-click="type='name'"></button>
<button ng-click="type='year'"></button>
<button ng-click="type='other'"></button>
答案 2 :(得分:0)
如果您的对象是数组,则可以使用内置的order-by filter。
只需在ng-options
中添加此行DiSchema.statics.all = function(o, cb){
this.model('Di').find(o, cb);
};
这假设您有一个&#39;名称&#39;属性,如果不将其更改为您想要排序的任何属性。
您可以使用&#39; - &#39;轻松扭转排序顺序。属性之前的运算符,例如
ng-options="p as p.name for p in data | orderBy : 'name'