2012-10-14 57 views
4

@repeat非常有用;不过,我正在用嵌套窗体打一个路障。zip格式@repeat嵌套格式

我需要制作一个游戏时间表,它有2个属性,时间表数据(游戏日期,时间,地点,对手)和提交团队注释(例如“由于冬季风暴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复合游戏数据和笔记分开。

这将是真的,真的很高兴: @repeat(_form("composite").zip(_form("note")), min=numGames) { case(fc,fn)=>

在嵌套的表单元素。

有反正我可以把它关掉吗?展望at the source它似乎没有,但也许有皮条客我的图书馆有可能(或者,因为我建立对2.1,劈东西的地方,直到框架支持似乎是一个限制)

回答

4

编辑
实际上,我最初的尝试使产出田地的数量增加了一倍;这一个生成正确的数量的字段:

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+"]"))) 
    } 
    } 
} 

尽管如此TBD如果编辑形式地图形成的数据值适当地....

ORIGINAL
进行实验,此编译:

// 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") 
} 

,并根据需要一起生成游戏数据和笔记。

至于它是否适用于窗体编辑,TBD ;-)