简体   繁体   English

Grails的: <g:each> 标签,排序属性

[英]Grails: <g:each> tag, sort attribute

There is a way to sort in the tag in 'desc'? 有一种方法可以在'desc'中对标签进行排序吗? And is it possible to sort by two columns? 是否可以按两列排序? I know that there is the possibility to pass the element already sorted in the controller but would be useful to have the chance also in the gsp tag. 我知道有可能传递已经在控制器中排序的元素,但是在gsp标签中也有机会。

Not optimal, but in a pinch you can sort the collection inline: 不是最佳,但在紧要关头,你可以内联排序集合:

<g:each in="${[2,3,6,1,10].sort{a,b -> a < b ? -1 : 1}}">
${it}
</g:each>

In general I agree with mfloryan. 总的来说,我同意mfloryan。 Putting logic in the view is a slippery slope, but there's a time and a place for everything. 在视图中放置逻辑是一个滑坡,但是有时间和地点适合一切。

That is correct. 那是对的。 The <g:each> tag does not support sorting and I don't think it should. <g:each>标记不支持排序,我认为不应该。 Any logic (like setting sort order) should not live in the view itself. 任何逻辑(如设置排序顺序)都不应该存在于视图本身中。

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

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