Play Framework - Using Javascript Variable in Scal

2019-01-18 13:41发布

So I have something that looks like this:

<script>
$(document).ready(function(){
  $("button.fadeMeOut").click(function(){
      var fadeID = $(this).attr('id');
      window.location.href = '@routes.Application.function(fadeID)';
  });
});
</script>

Of course this code will give a not found: value fadeID error. Is there a way for me to do something like this in Play Scala template?

2条回答
你好瞎i
2楼-- · 2019-01-18 14:03

You can insert the relative URL in place of '@routes.Application....etc'

So for example "/function/" + fadeID

If the route of @routes.Application.function is /function

查看更多
仙女界的扛把子
3楼-- · 2019-01-18 14:10

You can not mix Scala variables (server-side) with JS variables (client-side) as they are generated in quite distant environments.

Instead you can use for an example Play's javascriptRoutes like described in other question

查看更多
登录 后发表回答