grails数据绑定从选择中获取id
嘿。我有这样的东西:
class Car{
String name
}
class Volante{
String name
Car car
}
我的 gsp 文件:
<g:form controller="volante" action="save">
<label>Car</label>
<g:select name="car.id" from="${cm.Car.list()}" optionKey="id" value="${car?.id}" /><br><br><br>
<label>name
</label>
<input type="text" name="name" value="${volante?.name}" />
</g:form>
def save = {
def volante= new Volante()
volante.car = params.car.id ################
volante.name = params.name
if (!volante.save(failOnError: true)) {
render (view: "/participatedAdd", model : [volante: volante])
return
}
render(view: "/participated")
}
我有问题,我有 ###########。怎么可以这样=?我不知道如何获取链接到 volante.car 的汽车 ID。任何帮助将不胜感激。
附言。我不使用 def volante= new Volante(params) 因为我的观点比这更复杂。 我是否必须使用视图“className.attribute”中的值?因为我绑定了多个域类。?
hey. i have something like this:
class Car{
String name
}
class Volante{
String name
Car car
}
And my gsp file:
<g:form controller="volante" action="save">
<label>Car</label>
<g:select name="car.id" from="${cm.Car.list()}" optionKey="id" value="${car?.id}" /><br><br><br>
<label>name
</label>
<input type="text" name="name" value="${volante?.name}" />
</g:form>
def save = {
def volante= new Volante()
volante.car = params.car.id ################
volante.name = params.name
if (!volante.save(failOnError: true)) {
render (view: "/participatedAdd", model : [volante: volante])
return
}
render(view: "/participated")
}
I have problems where i have the ###########. How can do this like that=? I dont know how to get the car id to link to the volante.car. Any help would be apreciated.
PS. i dont use def volante= new Volante(params) because my view is more complex than this.
And do i have to use in the values from the view "className.attribute" ?? Because im binding multiple domain classes.?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你尝试过这样的事情吗?
Have you tried something like this ?
您可以尝试:
但是您也可以使用 Grails 的数据绑定来绑定特定属性:
由于参数名称是
car.id
,Grails 会识别出您正在通过 id 映射关联并绑定给你的。You might try:
But you could also just use Grails' data binding to bind the specific property:
Since the parameter name is
car.id
, Grails will recognize that you're mapping the association by id and bind it for you.