我拼命地尝试从表单提交中接收值列表并将其绑定到对象列表。
有效的是检索单行:
//class
case class Task(name: String, description: String)
val taskForm: Form[Task] = Form(
mapping(
"name" -> text,
"description" -> text
)(Task.apply)(Task.unapply)
)
//form
<tr>
<td><input name="name" type="text" class="span2" placeholder="Name..."></td>
<td><textarea name="description" class="autoexpand span7" rows="1" placeholder="Description..."></textarea>
</td>
</tr>
//receiving action:
val task = taskForm.bindFromRequest.get
但是现在我想提交多个任务类型的对象,例如:
<tr>
<td><input name="name[0]" type="text" class="span2" placeholder="Name..."></td>
<td><textarea name="description[0]" class="autoexpand span7" rows="1" placeholder="Description..."></textarea></td>
</tr>
<tr>
<td><input name="name[1]" type="text" class="span2" placeholder="Name..."></td>
<td><textarea name="description[1]" class="autoexpand span7" rows="1" placeholder="Description..."></textarea></td>
</tr>
现在执行 taskForm.bindFromRequest.get 失败。
有人想出解决方案吗?还是您对这种情况的处理方式完全不同?