简体   繁体   English

播放框架JavaScript路线+非静态方法

[英]Play framework javascript routes + non static methods

Is it possible for Javascript routes be used with non-static controller methods (ie route methods prefixed with @ for DI) ? 是否可以将Javascript路由与非静态控制器方法(即,以DI开头的@的路由方法)一起使用?

For example 例如

GET     /foo     @controllers.Foo.bar()

...

public static Result jsRoutes(){
    response().setContentType("text/javascript");
    return ok(Routes.javascriptRouter("jsRoutes",
        // Fails to compile
        controllers.routes.javascript.Foo.bar(),
        // Also fails to compile (cant find symbol JavascriptReverseRoute)
        Router.JavascriptReverseRoute.apply("controllers.Foo.bar",
        "function() {return _wA({method:'GET', url: /foo })}")) 
    );
}

Any guidance would be appreciated. 任何指导将不胜感激。 If its impossible then i dont mind using regular ajax but it would be a nice feature to have. 如果不可能,那么我不介意使用常规的ajax,但这将是一个不错的功能。

我的建议是尽量不要对JsRoute使用反向路由,而要使用相关的直接URL(为方便起见)将JS编译到控制器端点之外,并保持Controller具体无静态(因此,对于外部服务)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM