如何按字母顺序检索列表中的成员?
我有一个组织类,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要以某种方式更改您的班级,以便为成员命名!
因此,我们假设您的类是:
然后您有两种方法按字母顺序对成员进行排序。
第一种方法:您可以检索所有成员,然后将它们排序,如下所示:
第二种方法:您可以直接从 GORM 按字母顺序检索成员
First, you need to change somehow your classes in order to have a name for members !
So let's assume that your classes are:
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:
Second Method : You retrieve members directly from GORM in alphabetical order