gpt4 book ai didi

grails - Grails遍历 Controller 中的对象

转载 作者:行者123 更新时间:2023-12-02 15:13:58 25 4
gpt4 key购买 nike

在Grails中,要在表中显示某物的列表,我通常执行以下操作:

我的 Controller 是

thingController {

def temp2 = something.findAllByXXX(yyy)

[temp : temp2]
}

在我看来,我有:
<g:each var="it" in="${temp}">
${it.someThing}
${it.someThingSomething}
<g:each>

我不知道这是否是最好的方法。是否有可能做完全相同的事情,但是不是调用所有对象,而是在gsp中遍历它们,而是在 Controller 端进行所有操作。意思是传递单个对象,而不是将所有对象传递给 View 。

最佳答案

I don't know if this is the best approach. Is it possible to do this exact same thing, but instead of calling all the objects, and then in the gsp iterate over them, do this all controller-side. Meaning, instead of passing all the objects to the view, pass single objects



我想我不明白您提出的替代上述代码的建议。但是AFAIK上面的代码是在GSP中显示项目列表的最常用方法,因此,除非它引起您特定的问题,否则我不会费心寻找替代方法。

关于grails - Grails遍历 Controller 中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8139655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com