我在表单和事件之间有多对多的关系,在使用连接表的列表中,当我在编辑模式下显示数据时,我在表中的自己的下拉列表中显示每个项目,而不是一个多选下拉列表。如果我想添加更多项目,我还有一个小 jQuery 可以在其中添加额外的下拉列表,我的问题是,我如何按顺序保存这组“事件”?代码如下: -
初始 _form.gsp 加载表单的所有链接事件:-
<table id="eventList">
<g:each in="${formInstance?.events}" status = "i" var="item">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<td>
<label></label>
<g:select name="event_${i}" from="${framework.Event.list()}" required="required" optionKey="id" value="${item.id}" />
</td>
</tr>
</g:each>
</table>
使用此 gsp 添加其他对象
<tr class="${((newRow+1) % 2) == 0 ? 'even' : 'odd'}">
<td>
<label></label>
<g:select name="event_${newRow-1}" from="${framework.Event.list()}" required="required" optionKey="id" />
</td>
</tr>
目前的保存按钮是这样的: -
<g:actionSubmit class="save" action="update" value="${message(code: 'default.button.update.label', default: 'Update')}" />
并且更新操作与域设置自动生成的操作相同。如何保存以识别添加的新字段?即使我更改了顺序,当前点击保存对“事件”也是如此……
域类就是这样
import java.util.List;
class Form {
static constraints = {
formDesc(blank:false,maxSize:100,unique: true)
}
static mapping = {
table "form"
version false
columns{
id column:"form_id"
formDesc column:"description"
testscenarios joinTable:[name:"lnk_scenario_form",key:'form_id']
events joinTable:[name:"lnk_form_event",key:'form_id']
}
}
String formDesc
List events
static hasMany = [testscenarios:TestScenario, events:Event]
static belongsTo = fartframework.TestScenario
String toString (){
"${formDesc}"
}
}
和
class Event {
static constraints = {
eventTypeID()
eventOrder()
objectID()
testDataID()
}
static mapping = {
table "event_form"
version false
columns{
id column:"event_form_id"
eventTypeID column:"event_id"
eventOrder column:"event_order"
testDataID column:"test_data_id"
objectID column:"object_id"
forms joinTable:[name:"lnk_form_event", key:'event_id']
}
}
EventType eventTypeID
Integer eventOrder
TestData testDataID
Object objectID
static hasMany = [forms:Form]
static belongsTo = fartframework.Form
String toString (){
"${eventTypeID}"
}
}