如何将参数从scala.html传递到play框架中的javascript?

时间:2016-01-07 03:02:09

标签: javascript scala

@(message: String)(exchangelist: java.util.ArrayList[String])(implicit session: play.mvc.Http.Session)
@main(title = message)(session) {
<head>
...
</head>
<body>
  <script>
     startup(exchangelist);
  <script>
</body>

这样的代码,如何传递参数&#34; exchangelist&#34;到Js功能&#34; startup()&#34;?这种方法不起作用。

1 个答案:

答案 0 :(得分:0)

我建议尝试元标记:

&#13;
&#13;
    <html>
        <head>
            <!-- <meta name="exchangelist" content='@{exchangelist.mkstring(",")}'> -->
            <meta name="exchangelist" content='yellow,black,green'>
            <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
        </head>

        <script>
            function startup(list) {
                alert("startup called with " + list);
            }

            var el = $('meta[name=exchangelist]').attr("content").split(",");
            startup(el);
        </script>
    </html>
&#13;
&#13;
&#13;