此方法在数据库中添加表单数据。但它只读取第一种形式,从中读取并在所有日期和时间写入相同的数据。它没有看到其他形式更低。我该如何更改此方法?
def addPoints = Action.async {
implicit request =>
PointForm.form.bindFromRequest.fold(
errorForm => Future.successful(Ok(views.html.index(errorForm, Seq.empty[Point], days, times))),
data => {
for (d <- days) {
for (t <- times) {
if (data.subject != null) {
val newPoint = Point(0, data.subject, d, data.groupName, data.kind, formatTime(t), data.teacher, data.auditorium)
PointService.addPoint(newPoint)
}
}
}
PointService.listAllPoints.map(res => Redirect(routes.PointController.index()))
}
)
}
这是用于显示这些表单的html代码,因为您可以看到它们处于循环中,因此它们显示d * t次。如何从中收集有关它们具有相同名称的数据?
@(pointform: Form[models.PointFormData], points: Seq[models.Point], days: Seq[String], times: Seq[String])(implicit request: RequestHeader)
@main() {
<form id="point-data-form" role="form" action='@routes.PointController.addPoints()' method="post" class="form-horizontal" align="center" autocomplete="off">
<input type="text" id="groupName" name="groupName" value="" placeholder="Name of Group" class="form-control input-lg" required>
@for(d <- days) {
<h3>@d</h3>
@for(t <- times) {
@t
<div> <input type="text" id="subject" name="subject" value="" placeholder="Subject" class="form-control input-lg" >
<input type="text" id="kind" name="kind" value="" placeholder="Type" class="form-control input-lg" >
<input type="text" id="teacher" name="teacher" value="" placeholder="Teacher" class="form-control input-lg" >
<input type="number" id="auditorium" name="auditorium" value="" placeholder="Auditorium" class="form-control input-lg" >
</div>
}
}
<div class="form-actions controls ynt-btn-xlarge">
<button type=submit class="btn btn-primary ynt-btn-orange">Add</button>
</div>
</form>