Grails在GSP站点内部使用grails var [英] Grails using grails var in GSP Site inside javascript

查看:121
本文介绍了Grails在GSP站点内部使用grails var的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如:我有一个会话值 session.getAttribute(我的解决方案现在(在一个GSP中):

$ b


$ b

 <%
def js = new String(< script type = \text / javascript\>)
js + =var jsSelectedValue =+ session.getAttribute(selectedValue)+;
js + =< / script>
out<< js
%>

然后我在我的GSP中使用jQuery Stuff等的JavaScript块,我需要这个值。

有没有另外一种方法可以在纯javascript代码中使用grails变量?

第二个问题,正好相反。我选择例如在一个下拉框中,然后单击保存,然后我想要将值$(#select-box)。val()存储在来自JS-part的会话变量中。



非常感谢您的帮助。

干杯,

Marco

解决方案

为什么不使用JavaScript GSP标签?解决方案可能如下所示:

 < g:javascript> 
var jsSelectedValue =$ {session.selectedValue};
< / g:javascript>


I have a question using grails variable values in javascript code in a GSP file.

For Example: I have a session value session.getAttribute("selectedValue") and I want to use this value inside javascript code part.

My solution is now (inside a GSP):

<%
    def js = new String("<script type=\"text/javascript\">")
    js += "var jsSelectedValue = " + session.getAttribute("selectedValue") + ";"
    js += "</script>"
    out << js
%>

and then I have javascript block inside my GSP with jQuery Stuff and so on, there I need this value.

Is there another way to have grails variables accessible inside pure javascript code?

And second question, the exactly other way around. I select for example in a dropdown box and click "save" and then i want to store the value $("#select-box").val() inside a session variable from JS-part.

Thank you very much in advance for your help.

Cheers,

Marco

解决方案

Why do not use the javascript GSP-tag? A solution can look like this:

<g:javascript>
    var jsSelectedValue = "${session.selectedValue}"; 
</g:javascript>

这篇关于Grails在GSP站点内部使用grails var的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆