如何直接从控制器向Grails中的JavaScript文件传递值 [英] How to pass a value directly from a controller to a javascript file in Grails
问题描述
想要直接从控制器传递给JavaScript文件。
TestControler.groovy
def list(){
渲染(view:list,model:[theId:theId])
}
Test.js
函数test(){
//使用Id
做$ sm}
发现的解决方案在中间有已呈现的gsp,即这一个,但我想知道是否有办法避免这包括使用隐藏字段或在gsp文件中包含JavaScript代码片段,例如:
< g:javascript>
函数测试($ {theId}){
//用
做$ sm
< / g:javascript>
不幸的是,似乎没有任何内容涵盖了什么您正在寻找。我见过并使用过自己的最佳方法是在gsp / html中使用隐藏字段,并从客户端的javascript中检索这些值。
Would like to pass directly from the controller to a JavaScript file.
TestControler.groovy
def list() {
render (view: "list", model:[theId: theId])
}
Test.js
function test() {
// do smth with theId
}
Found solution have the rendered gsp in the middle, i.e. this one, but I would like to know if there is a way to avoid that including using hidden fields or having in the gsp file a javascript code snippet such as:
<g:javascript>
function test(${theId}) {
// do smth with theId
}
</g:javascript>
Unfortunately there does not seem to be anything that covers what you're looking for. The best approach that I have seen, and have used myself, is to use hidden fields in the gsp/html, and retrieve those values from javascript on the client side.
这篇关于如何直接从控制器向Grails中的JavaScript文件传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!