我有 3 个类,我想将 3 个列表返回到模板中,这些列表在我的数据库是 MongoDB 中使用
def addCourse = Action.async {implicit request =>
val teacherCollection = db.collection[BSONCollection]("Teacher")
val courseColl = subjectCollection.find(BSONDocument()).cursor[Subject].collect[List]()
val teacherColl = teacherCollection.find(BSONDocument()).cursor[Teacher].collect[List]()
courseColl.map { course =>
val sam = teacherColl.map{teacher=>
teacher
}
Ok(views.html.Course.addNewCourse(course,sam,Course.form))
}
}
模板代码:
@(subject:List[models.Subject],teacher:List[models.Teacher],myForm: Form[models.Course])
我有一个错误:类型不匹配期望 List[Teacher] ,实际 Future[List[Teacher]]
我要做什么?
注意:如果我将 Ok(views...) 放入 val sam map,编译器会显示错误,这听起来像是异步错误,因为“异步”将是红色的
Error:(59, -1) Play 2 Compiler:
/app/controllers/School.scala:59: type mismatch;
found : Unit
required: play.api.mvc.Result