Play Framework - Using Javascript Variable in Scala Template

拜拜、爱过 提交于 2019-12-17 19:22:10

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/17817174/play-framework-using-javascript-variable-in-scala-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!