Grails 一对多关系视图
我有两个 grails 域类
Class MultipleChoiceQuestion {
String question
static constraints = {
...
}
static hasMany = [options:MultipleChoiceOption]
}
,
class MultipleChoiceOption{
String answerOption
boolean correctOption
MultipleChoiceQuestion question
static constraints = {
...
}
}
我希望我的用户能够创建一个问题,然后添加至少 3 个选项,而无需导航/单击不同的屏幕。
我的第一个问题是我必须生成视图并开始编辑代码吗?
如果上述问题的答案是肯定的,那么我的第二个问题是,在一个表单提交中保存问题以及多个选项的最佳方法是什么? 对于每个选项,生成的代码将具有如下所示的内容。
<g:textField name="answerOption" value="${answerOptionInstance?.answerOption}"/>
<g:checkBox name="correctOption" value="${answerOptionInstance?.correctOption}"/>
我怎样才能在一个页面中有多个这样的元素? 请查看线框以了解我想要实现的目标,对于创建不良的线框,我深表歉意。 单击链接以在浏览器中打开图像 http://cynosuredev.com/wf.png
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不愿意,则不必使用 Grails 脚手架。由于这是一种非常专业的形式,因此您应该自己构建 HTML。我在 github 创建了一个测试项目,它展示了解决此问题的良好设计。一探究竟。
You don't have to use Grails scaffolding if you don't want to. Since this is a pretty specialized form, you should construct the HTML yourself. I've created a test project at github that shows a good design for this problem. Check it out.