如何将 ng-select group by 用于布尔值、顺序和标签?
How can I use ng-select group by for boolean value, with an order and label?
我有一些数据:
0: {id: 1, name: "hhh", description: "hhh", isPopular: false,…}
1: {id: 2, name: "bbb", description: "bbb", isPopular: true,…}
2: {id: 3, name: "ccc", description: "ccc", isPopular: false,…}
3: {id: 4, name: "ddd", description: "ddd", isPopular: true,…}
4: {id: 5, name: "aaa", description: "aaa", isPopular: false,…}
5: {id: 6, name: "ggg", description: "ggg", isPopular: false,…}
我想在 ng-select 中显示为:
Popular
bbb
ccc
The rest
aaa
ccc
ggg
hhh
所以我用过
<select ng-selected="true"
ng-options="category.name group by category.isPopular for category in ctrl.categories |
orderBy: ['-isPopular','name']"
ng-model="myModel.category">
</select>
然而这是返回:
aaa
ccc
ggg
hhh
true
bbb
ccc
如何标记组并按组排序?
我很确定如果你想分组你应该使用这个:
<select ng-selected="true"
ng-options="category.name for category in ctrl.categories |
groupBy: 'category.isPopular' |
orderBy: ['-isPopular','name']"
ng-model="myModel.category">
</select>
groupBy
在 Angular-filter 中,因此您必须正确使用语法。
您需要将群组名称传递给group by
。例如:
<select ng-selected="true"
ng-options="category.name group by category.isPopular ? 'Popular' : 'The rest' for category in ctrl.categories |
orderBy: ['-isPopular','name']"
ng-model="myModel.category">
</select>
我有一些数据:
0: {id: 1, name: "hhh", description: "hhh", isPopular: false,…}
1: {id: 2, name: "bbb", description: "bbb", isPopular: true,…}
2: {id: 3, name: "ccc", description: "ccc", isPopular: false,…}
3: {id: 4, name: "ddd", description: "ddd", isPopular: true,…}
4: {id: 5, name: "aaa", description: "aaa", isPopular: false,…}
5: {id: 6, name: "ggg", description: "ggg", isPopular: false,…}
我想在 ng-select 中显示为:
Popular
bbb
ccc
The rest
aaa
ccc
ggg
hhh
所以我用过
<select ng-selected="true"
ng-options="category.name group by category.isPopular for category in ctrl.categories |
orderBy: ['-isPopular','name']"
ng-model="myModel.category">
</select>
然而这是返回:
aaa
ccc
ggg
hhh
true
bbb
ccc
如何标记组并按组排序?
我很确定如果你想分组你应该使用这个:
<select ng-selected="true"
ng-options="category.name for category in ctrl.categories |
groupBy: 'category.isPopular' |
orderBy: ['-isPopular','name']"
ng-model="myModel.category">
</select>
groupBy
在 Angular-filter 中,因此您必须正确使用语法。
您需要将群组名称传递给group by
。例如:
<select ng-selected="true"
ng-options="category.name group by category.isPopular ? 'Popular' : 'The rest' for category in ctrl.categories |
orderBy: ['-isPopular','name']"
ng-model="myModel.category">
</select>