无法获取javascriptRoutes一起玩框架2工作 [英] Can't get javascriptRoutes to work with Play Framework 2

查看:145
本文介绍了无法获取javascriptRoutes一起玩框架2工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 javascriptRoutes 在播放2(斯卡拉),我得到一个错误(见下文)。这是我做的:

I'm trying to use javascriptRoutes in Play 2 (Scala) and I am getting an error (see below). Here is what I did:

def javascriptRoutes = Action { implicit request =>
    import routes.javascript._
    Ok(Routes.javascriptRouter("jsRoutes")(Orders.searchProducts))
        .as("text/javascript")
}

添加路由路线文件

Add route to routes file

GET    /assets/javascripts/routes    controllers.Application.javascriptRoutes

添加<脚本> 进口 main.scala.html

Add <script> import to main.scala.html

<head>
...
<script type="text/javascript" src="@routes.Application.javascriptRoutes"></script>
...
</head>

通过这些更改后,我收到以下错误在JavaScript控制台:

With these changes in place I am getting the following error in the JavaScript console:

GET http://localhost:9000/assets/javascripts/routes 404 (Not Found)
Uncaught ReferenceError: jsRoutes is not defined

我在想什么?

What am I missing?

推荐答案

错误的顺序在的conf /路线在文件可能会导致问题。

wrong order within the conf/routes file may cause the issue.

有一个提示:

<一个href="http://grokbase.com/t/gg/play-framework/1348rbs2vk/2-1-scala-javascript-router-404">http://grokbase.com/t/gg/play-framework/1348rbs2vk/2-1-scala-javascript-router-404

有一次我按照提示调整顺序:

once I adjusted the order according to the hint:

将JavaScript的路由器的动作上面的路由定义   资产路线。

Move the route definition of the javascript router action above the assets route.

这个问题是固定的。

    # Routes
    # This file defines all application routes (Higher priority routes first)
    # ~~~~

    GET     /                           controllers.MainController.index()
    GET     /message                    controllers.MessageController.getMessage()
    GET     /assets/javascripts/routes  controllers.MessageController.javascriptRoutes()

    # Map static resources from the /public folder to the /assets URL path
    GET     /assets/*file               controllers.Assets.at(path="/public", file)
    GET     /webjars/*file              controllers.WebJarAssets.at(file)`

这篇关于无法获取javascriptRoutes一起玩框架2工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆