简体   繁体   English

在Groovy中排序集合

[英]Sorting collection in groovy

I have code like this in a GSP: 我在GSP中有这样的代码:

<g:each in="${cifUserInstance.cif?.servicePackage?.transactions?.collect{it.service}}" status="i" var="transaction">

But the resulting data is not sorted; 但是结果数据没有排序; they are displayed randomly. 它们是随机显示的。 How can I sort the data using the code above? 如何使用上面的代码对数据进行排序?

Try: 尝试:

<g:each in="${cifUserInstance.cif?.servicePackage?.transactions?.collect{it.service}.sort()}" status="i" var="transaction">

BTW, it's better to prepare all data in controller, and use view's gsp only to show result data 顺便说一句,最好在控制器中准备所有数据,并仅使用视图的gsp显示结果数据

这是黑暗中的一枪,却看不到“交易”和“服务”的模样,但是您可以尝试一下,

<g:each in="${cifUserInstance.cif?.servicePackage?.transactions?.service.sort()}" status="i" var="transaction">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM