这可能比Play相关的Scala更多,但我在一些Play代码中遇到了这个问题。
我有
def index = Action.async { implicit request =>
val content1Future = Blogs.getAllBlogs(request)
val sidebar1Future = Blogs.getAllBlogsOverview(request)
for {
sidebar1 <- sidebar1Future
content1 <- content1Future
sidebar1Body <- Pagelet.readBody(sidebar1)
content1Body <- Pagelet.readBody(content1)
} yield {
val sidebarcontents = List(sidebar1Body)
val contents = List(content1Body)
Ok(views.html.main("Index", contents, sidebarcontents)).withHeaders(("Cache-Control", "no-cache"))
}
它工作正常。
现在,我尝试将for-comprehention提取到一个单独的函数中来处理&#39; sidebar&#39;我想传递内容&#39;。
像
def index = Action.async { implicit request =>
standardMain(Blogs.getAllBlogs(request))
}
def standardMain(content1Future: => Future[Result])(implicit request: Request[_]) : Future[Result] = {
val sidebar1Future = Blogs.getAllBlogsOverview(request)
for {
sidebar1 <- sidebar1Future
content1 <- content1Future
sidebar1Body <- Pagelet.readBody(sidebar1)
content1Body <- Pagelet.readBody(content1)
} yield {
val sidebarcontents = List(sidebar1Body)
val contents = List(content1Body)
Ok(views.html.main("Index", contents, sidebarcontents)).withHeaders(("Cache-Control", "no-cache"))
}
}
但后来我
[info]将1个Scala源编译为D:\ Dropbox \ Playground \ PlayWorld \ play-with-forms \ target \ scala-2.11 \ classes ...
[错误] D:\ Dropbox \ Playground \ PlayWorld \ play-with-forms \ app \ controllers \ Application.scala:91:type mismatch;
发现[错误]:scala.concurrent.Future [play.api.mvc.Result]
[error] required:play.api.libs.iteratee.Iteratee [Array [Byte],?]
[error] content1&lt; - content1Future
[错误] ^
[错误] D:\ Dropbox \ Playground \ PlayWorld \ play-with-forms \ app \ controllers \ Application.scala:90:type mismatch;
发现[错误]:play.api.libs.iteratee.Iteratee [Array [Byte],Nothing]
[error] required:scala.concurrent.Future [play.api.mvc.Result]
[error] sidebar1&lt; - sidebar1Future
[错误] ^
[错误]发现两个错误
[error](编译:编译)编译失败
[错误]申请 -
我尝试了很多不同的调用,但不知怎的,我不知道如何获得play.api.libs.iteratee.Iteratee [Array [Byte],?]。
我怎样才能实现这个目标。感谢。