Forms Scala-Play:如何将表单字段绑定到向量?
在Play 2.6中,重复元素的默认表单绑定为Forms Scala-Play:如何将表单字段绑定到向量?,forms,scala,vector,playframework,binding,Forms,Scala,Vector,Playframework,Binding,在Play 2.6中,重复元素的默认表单绑定为Seq、List和Set,例如: Form( "name" -> seq(text) ) 但是,我在几个场景中使用Vector collection type,因为它比默认的Seq或Iterable实现(即List)具有更好的总体性能(例如,对于基于索引的访问),这是List(如果进行索引搜索,处理头部或尾部元素的线性时间的性能很好) 在当前重头戏2.6中,Vector或IndexedSeq(默认为Vector)没有任何默认表单绑定 映射
Seq
、List
和Set
,例如:
Form(
"name" -> seq(text)
)
但是,我在几个场景中使用Vector collection type,因为它比默认的Seq
或Iterable
实现(即List
)具有更好的总体性能(例如,对于基于索引的访问),这是List
(如果进行索引搜索,处理头部或尾部元素的线性时间的性能很好)
在当前重头戏2.6中,Vector
或IndexedSeq
(默认为Vector
)没有任何默认表单绑定
映射向量的默认方法是什么?您可以这样定义自己的映射
def vector[A](mapping: Mapping[A]): Mapping[Vector[A]] =
RepeatedMapping(mapping).transform(_.toVector, _.toList)
Form(
"name" -> vector(text)
)
然后像这样使用它
def vector[A](mapping: Mapping[A]): Mapping[Vector[A]] =
RepeatedMapping(mapping).transform(_.toVector, _.toList)
Form(
"name" -> vector(text)
)