3

ReactiveMongo で mongo インスタンスを呼び出すときに、理解を深めようとしています。このメソッドは、結果が返されるかどうかを確認し、返されない場合は Future(NotFound) を返す必要があります。しかし、理解できないエラーが発生します。

[info] Compiling 8 Scala sources and 1 Java source to /Users/Projects/reco_play/parser/target/scala-2.10/classes...
[error] /Users/Projects/reco_play/parser/app/controllers/Application.scala:94: value map is not a member of Object
[error]           }.getOrElse(Future(NotFound))
[error]                      ^
[error] one error found
[error] (compile:compile) Compilation failed

輸入品:

import play.api.mvc._
import play.api.Play.current
import play.api.Logger
import play.modules.reactivemongo.{ReactiveMongoPlugin, MongoController}
import models.{Company}
import reactivemongo.api.collections.default.BSONCollection
import reactivemongo.bson.{BSONObjectID, BSONDocument}
import org.joda.time.DateTime
import scala.concurrent.{Future, ExecutionContext}

方法:

def showEditForm(id: String) = Action {
    implicit request =>
      implicit val reader = Company.CompanyReader
      Async {
        val objectId = new BSONObjectID(id)
        val cursor = collection.find(BSONDocument("_id" -> objectId)).cursor[Company]

        for {
          maybeCompany <- cursor.headOption
          result <- maybeCompany.map { company =>
              Ok(views.html.editForm(Some(id), Company.form.fill(company)))
          }.getOrElse(Future(NotFound))
        } yield result
      }
  }
4

2 に答える 2

0

多分あなたはこのようなことを試すことができます。

  for {
    maybeCompany <- cursor.headOption
    result <- maybeCompany.map { company =>
      Promise.successful(
        Ok(views.html.editForm(Some(id), Company.form.fill(company)))
      ).future
    }.getOrElse(Future(NotFound))
  } yield result
于 2013-05-03T14:53:24.247 に答える