我有一个Play2模板:
files: Option[List[(String, reactivemongo.api.gridfs.ReadFile[reactivemongo.bson.BSONValue])]]
我想显示的文件在下拉表单选择,但只有当文件在那里!
我该怎么做呢?
正如Julien Lafont所说,在将此列表提供给模板之前,您应该考虑对其进行转换。例如,如果您只想要一个读取文件列表(可以调用filename
和id
):
val fileList = files.toList.flatten.map(_._2) // fileList is a List[ReadFile[BSONValue]]]
如果你只想获得文件名和它们的id(假设它们的id是BSONObjectID
s),你可以这样写:
val fileList = files.toList.flatten.map { file =>
val id = file._2.id match {
case oid: BSONObjectID => oid.stringify
case id => id.toString
}
id -> file._2.filename
}
// fileList is a List[(String, String)] where the first element of the tuple is a string version of the id and the second is the name of the file.