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

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

问题描述

我有两个 grails 域类

 类 MultipleChoiceQuestion {字符串问题静态约束 = {...}静态 hasMany = [options:MultipleChoiceOption]}

class MultipleChoiceOption{字符串答案选项布尔正确选项多项选择题静态约束 = {...}}

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

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

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

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

如何在一页中包含多个这样的元素?请查看线框以了解我想要实现的目标,对于创建不佳的线框,我深表歉意.单击用于在浏览器中打开图像的链接

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天全站免登陆