1

我有一个 Play2 模板:

files: Option[List[(String, reactivemongo.api.gridfs.ReadFile[reactivemongo.bson.BSONValue])]]

我想在下拉表单中显示文件选择,但前提是文件在那里!

我该怎么做?

4

1 回答 1

0

正如 Julien Lafont 所说,您应该考虑在将此列表提供给您的模板之前对其进行转换。例如,如果您只想要一个读取文件列表(您可以在其上调用filenameand id):

val fileList = files.toList.flatten.map(_._2) // fileList is a List[ReadFile[BSONValue]]]

如果你只想获取文件名和它们的 id(假设它们的 id 是BSONObjectIDs),你可以这样写:

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.
于 2013-03-14T12:36:51.660 回答