【发布时间】:2014-07-24 22:05:32
【问题描述】:
这个下拉菜单几乎也是我想要的。我无法显示答案对象的body 属性或toString。
<g:select name="questionId"
from="${questionInstance.answers.id}"
value="${questionInstance.correctAnswer.id}"
noSelection="['':'Select a Module']" />
不幸的是,无论我尝试什么组合,我都无法获得下拉菜单,默认情况下,选择correctAnswer,而不使用from 属性中的id。
<g:select name="questionId"
from="${questionInstance.answers}"
value="${questionInstance.correctAnswer}"
noSelection="['':'Select a Module']" />
我做错了什么?
问题
class Question {
DateTime dateCreated
DateTime lastUpdated
String body
Answer correctAnswer
Integer ordinal
static belongsTo = [lesson: Lesson]
static hasMany = [answers: Answer]
static constraints = {
body blank: false
correctAnswer nullable: true,
validator: { Answer val, Question obj ->
// Correct answer must have this as it's question
val ? val.question == obj : true // TODO: Give this a proper error message
}
ordinal unique: 'lesson'
}
static mapping = {
lesson lazy: false
answers sort: 'ordinal'
}
}
回答
class Answer {
DateTime dateCreated
DateTime lastUpdated
String body
Integer ordinal
String reason
static belongsTo = [question: Question]
static constraints = {
body blank: false
ordinal unique: 'question'
reason blank: false
}
static mapping = {
question lazy: false
}
String toString() {
"Answer: $body"
}
}
【问题讨论】:
标签: grails