我正在尝试javascriptRoutes
在 Play 2 (Scala) 中使用,但出现错误(见下文)。这是我所做的:
向控制器添加javascriptRoutes
方法Application
def javascriptRoutes = Action { implicit request =>
import routes.javascript._
Ok(Routes.javascriptRouter("jsRoutes")(Orders.searchProducts))
.as("text/javascript")
}
将路由添加到routes
文件
GET /assets/javascripts/routes controllers.Application.javascriptRoutes
添加<script>
导入到main.scala.html
<head>
...
<script type="text/javascript" src="@routes.Application.javascriptRoutes"></script>
...
</head>
进行这些更改后,我在 JavaScript 控制台中收到以下错误:
GET http://localhost:9000/assets/javascripts/routes 404 (Not Found)
Uncaught ReferenceError: jsRoutes is not defined
我错过了什么?