Forms zip样式@repeat over嵌套表单
Forms zip样式@repeat over嵌套表单,forms,scala,nested,playframework-2.0,repeat,Forms,Scala,Nested,Playframework 2.0,Repeat,@repeat非常有用;但是,我遇到了嵌套表单的障碍 我需要制作一个游戏时间表的表格,它有两个属性,时间表数据(游戏日期、时间、地点、对手)和提交团队笔记(例如,“由于冬季风暴,1月7日的游戏已移至1月9日在…夏威夷;-”) 表单映射基于: case class Schedule( composite: Seq[Composite], note: Seq[ScheduleNote] ) 然后在模板中显示表单,我有: @repeat(_form("composite"), min=nu
@repeat
非常有用;但是,我遇到了嵌套表单的障碍
我需要制作一个游戏时间表的表格,它有两个属性,时间表数据(游戏日期、时间、地点、对手)和提交团队笔记(例如,“由于冬季风暴,1月7日的游戏已移至1月9日在…夏威夷;-”)
表单映射基于:
case class Schedule(
composite: Seq[Composite],
note: Seq[ScheduleNote]
)
然后在模板中显示表单,我有:
@repeat(_form("composite"), min=numGames) { f=>
@inputDate(f("gameDate"), 'id-> "gameDate", '_label-> "Game Date")
....
}
@repeat(_form("note"), min=numGames) { f=>
@inputDate(f("gameNote"), '_label-> "Game Notes")
....
}
当然,游戏笔记需要与游戏数据配对,这在上面不会发生,因为看起来我需要分别重复组合游戏数据和笔记
如果能:
@repeat(_-form(“composite”).zip(_-form(“note”)),min=numGames){case(fc,fn)=>
在嵌套的表单元素上
无论如何,我都可以做到这一点吗?看起来似乎没有,但也许有一个皮条客我的库是可能的(或者,因为我是根据2.1构建的,所以在框架支持似乎是一个限制的东西之前,对一些东西进行适当的修改)编辑实际上,我最初的尝试将生成的字段数量增加了一倍;这一次生成了正确的字段数量:
object repeat2 {
import play.api.data.Field, play.api.templates.Html
def apply(field: (Field,Field), min: Int = 1)(f: (Field,Field) => Html) = {
field match{ case(a,b)=>
(0 until math.max(
if (a.indexes.isEmpty) 0 else a.indexes.max + 1, min)
).map(i => f.apply(a("["+i+"]"), b("["+i+"]")) )
}
}
}
如果正确编辑表单映射表单数据值,则仍待定
原创在实验中,这将编译:
// in a form utility object
object repeat2 {
import play.api.data.Field, play.api.templates.Html
def apply(field: (Field,Field), min: Int = 1)(f: Field => Html) = {
field match{ case(a,b)=>
(0 until math.max(
if (a.indexes.isEmpty) 0 else a.indexes.max + 1, min)
).map(i => f(a("["+i+"]")) + f(b("["+i+"]")) )
}
}
}
// then, importing above in a template
@repeat2( (_form("composite"), _form("note")), min=5) { f=>
@inputDate(f("gameDate"), 'id-> "gameDate", '_label-> "Game Date")
...
@inputDate(f("gameNote"), '_label-> "Game Notes")
}
并根据需要一起生成游戏数据和注释
至于它是否适用于表单编辑,待定;-)