简体   繁体   中英

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) ?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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