我正在尝试将案例类应用于Scala Play表单中的单个字段。我正在尝试将其应用于exerciseName
变量内的setsForm
字段。
case class ExerciseName(exerciseName:String)
case class WorkoutSet(exerciseName:ExerciseName, number:Int)
case class WorkoutSets(sets:List[WorkoutSet])
val setsForm:Form[WorkoutSets] = Form(
mapping(
"workoutSets" -> list(mapping
(
//i need to get exerciseName to be of type ExerciseName somehow...
"exerciseName" ->nonEmptyText,
"workoutSet" -> number(min=1,max=20)
)(WorkoutSet.apply)(WorkoutSet.unapply))
)(WorkoutSets.apply)(WorkoutSets.unapply)
)
我想知道是否有人可以为我提供任何见解。
谢谢!
答案 0 :(得分:1)
val setsForm:Form[WorkoutSets] = Form(
mapping(
"sets" -> list(
mapping(
"exerciseName" -> mapping("exerciseName" -> nonEmptyText)(ExerciseName.apply) (ExerciseName.unapply),
"workoutSet" -> number(min=1,max=20)
)(WorkoutSet.apply)(WorkoutSet.unapply)
)
)(WorkoutSets.apply)(WorkoutSets.unapply)
)
我还建议将ExerciseName的字段名称更改为" name"避免混淆。