AngularJs - ngOptions:如何通过组名,然后按标签订购 [英] AngularJs - ngOptions: How to order by Group Name and then by Label

查看:137
本文介绍了AngularJs - ngOptions:如何通过组名,然后按标签订购的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我有这种形式的以下数据数组:

Let's assume I have the following data array in this form:

var data = [{group:GroupA, label: BB}, {group:GroupB, label: DD}.....].

我的结合会是这样的:

My binding would be something like:

<select data-ng-options="c as c.label group by c.group for c in data"></select>

我想下拉,同时让他们每一组下也会分类列出所有与A组的项目组B之前。

I would like the dropdown to list all the items with GroupA before GroupB while having them also sorted under each group.

这样的事情。

GroupA
AA
BB
CC

GroupB
DD
EE
FF

我知道我可以使用OrderBy角过滤器,但并没有真正的工作,我需要的方式。我的猜测是我必须写一个自定义过滤器,手动顺序列出我想要的方式,但我不知道是否有更简单的方法来完成任务。

I know I can use the orderBy Angular filter, but that doesn't really work the way I need. My guess is I have to write a custom filter that manually order list the way I want, but I was wondering if there an easier way to accomplish the task.

谢谢!

推荐答案

排序依据可以采取多个参数通过订购的数组。所以,你可以这样做:

orderBy can take an array of multiple parameters to order by. So you can do:

c as c.label group by c.group for c in data | orderBy:['group','label']

这里是一个小提琴

这篇关于AngularJs - ngOptions:如何通过组名,然后按标签订购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆