gpt4 book ai didi

grails - Grails:如何从 View 中先前创建的对象列表中进行选择?

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

假设我有以下类(class):

package test

class Person {
String name

static hasMany = [stuff:Stuff]

static constraints = {
}
}


包装测试
class Stuff {
String stuff

static belongsTo = Person

static constraints = {
}
}

当我实现Person的 View 时,我希望能够从以前创建的东西列表中进行选择。我该如何实现?我看到,当我使用脚手架时,Grails会生成一个下拉菜单,我可以在其中执行此操作,但是由于我正在设计自己的 View ,因此我想了解如何完成此操作。

谢谢。

最佳答案

在这里开始查看select标记的文档可能是个好主意:https://gsp.grails.org/latest/ref/Tags/select.html

一个简单的示例,显示所有 Material 的列表,如下所示:

<g:select name="stuffSelect" from="${Stuff.list()}" optionKey="id" optionValue="stuff"/>

这将为您提供数据库中所有 Stuff的下拉列表,向用户显示String值,但在提交表单时提交DB ID。

关于grails - Grails:如何从 View 中先前创建的对象列表中进行选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52747524/

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