3

我有一些数据:

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 中显示为:

热门
bbb
ccc
其余
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
真实
bbb
ccc

我如何标记组并按组排序?

4

2 回答 2

3

您需要将组的名称传递给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>
于 2015-07-10T13:52:30.663 回答
2

我很确定如果你想分组你应该使用这个:

<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中,因此您必须正确使用语法。

于 2015-07-10T13:26:00.640 回答