Grails一对多的关系视图 [英] Grails one to many relationship view

查看:117
本文介绍了Grails一对多的关系视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个grails域类

 类MultipleChoiceQuestion {
字符串问题
static constraints = {
...
}
static hasMany = [options:MultipleChoiceOption]
}





 类MultipleChoiceOption {
字符串answerOption
布尔correctOption
MultipleChoiceQuestion问题
static constraints = {
...
}
}

我希望我的用户能够创建问题,然后添加至少3个选项,而无需在不同屏幕上导航/点击。



我的第一个问题我是否必须生成视图并开始编辑代码?



如果上述问题的答案是肯定的,那么我的第二个问题是,什么是保存问题的最佳方法一个表单中的多个选项提交?
生成的代码对每个选项都有类似的内容。

 < g:textField name =answerOption值= $ {?answerOptionInstance .answerOption}/> 

我如何在一个页面中有多个这样的元素?
请看线框以了解我想要达到的目标,对于创建的线框不好表示歉意。
点击链接在您的浏览器中打开图片


I have two grails domain classes

 Class MultipleChoiceQuestion {
    String question
    static constraints = {
        ...
    }
    static hasMany = [options:MultipleChoiceOption]
   }

and

class MultipleChoiceOption{
    String answerOption
    boolean correctOption
    MultipleChoiceQuestion question
    static constraints = {
        ...
    }
}

I want my users to be able to create a question then add atleast 3 options without navigating/clicking on different screens.

My first question is must I generate view and start editing code?

And if the answer to question above is yes then my second question is, what's the best way to save a question along with multiple options in one form submit? The generated code will have something like following for each option.

<g:textField name="answerOption" value="${answerOptionInstance?.answerOption}"/>
<g:checkBox name="correctOption" value="${answerOptionInstance?.correctOption}"/>

how can I have multiple such elements in one page? Please see the wireframe to get an idea of what I want to achieve, my apologies for poorly created wire frame. Click on the link for opening the image in your browser http://cynosuredev.com/wf.png

解决方案

maybe this site will help you http://omarello.com/2010/08/grails-one-to-many-dynamic-forms/

这篇关于Grails一对多的关系视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆