如何按字母顺序检索列表中的成员?

发布于 2024-08-25 14:02:34 字数 446 浏览 4 评论 0原文

我有一个组织类,

class Organization {
hasMany = [member:Members]
}

class Members {
belongsTo = organization
}

我正在打印所有成员,

<ol>
<g:each in="${organizationInstance?.members?}" var="m">
    <li><g:link controller="members" action="show" id="${m.id}">${m?.encodeAsHTML()}</g:link></li>
</g:each>
</ol>

我想对成员的打印进行排序,以便它按字母顺序打印。 有什么想法吗?

I have an organization class

class Organization {
hasMany = [member:Members]
}

class Members {
belongsTo = organization
}

I'm printing all the members using

<ol>
<g:each in="${organizationInstance?.members?}" var="m">
    <li><g:link controller="members" action="show" id="${m.id}">${m?.encodeAsHTML()}</g:link></li>
</g:each>
</ol>

I want to sort the printing of members so that it would print alphabetically.
any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心在旅行 2024-09-01 14:02:34

首先,您需要以某种方式更改您的班级,以便为成员命名!
因此,我们假设您的类是:

class Organization {
hasMany = [members:Member]
}

class Member {
belongsTo = organization
String name
}

然后您有两种方法按字母顺序对成员进行排序。

第一种方法:您可以检索所有成员,然后将它们排序,如下所示:

<g:each in="${organizationInstance?.members?.sort {it.name} }" var="m">

第二种方法:您可以直接从 GORM 按字母顺序检索成员

def members = Member.findAllByOrganization(organizationInstance, [sort: "name"])

First, you need to change somehow your classes in order to have a name for members !
So let's assume that your classes are:

class Organization {
hasMany = [members:Member]
}

class Member {
belongsTo = organization
String name
}

Then you have two ways of sorting the members in alphabetical order.

First method : you can retrieve all members and then sort them as shown below:

<g:each in="${organizationInstance?.members?.sort {it.name} }" var="m">

Second Method : You retrieve members directly from GORM in alphabetical order

def members = Member.findAllByOrganization(organizationInstance, [sort: "name"])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文