javascript - grails 链接 - 将 javascript 变量添加到 params 中

标签 javascript grails

$('#andiebox').append('<g:link controller="search" action="search" params="[where:'+destination+', what:what, sort:sort, type:type, distance:distance]">Psychos in HH</g:link>');

这不被grails接受,我怎样才能正确插入变量?

该变量是客户端从输入生成的:

var destination = $(this).attr("id");

            var metaSection = $("#metaSection").val(); 

最佳答案

<g:link是服务器端标签,因此它只能为您的链接准备基础。所有客户端参数均应在客户端填写。像这样的东西:

var params = { 
   what: '${what.encodeAsJavaScript()}', //as I understand all this variables are server side variables
   sort: '${sort.encodeAsJavaScript()}', 
   type: '${type.encodeAsJavaScript()}', 
   distance: '${distance.encodeAsJavaScript()}' 
}; 
params.destination =  $(this).attr("id");
var urlBase = '${createLink(controller:"search", action: "search").encodeAsJavaScript()}';

$('#andiebox').append('<a href="' + url + '?' + $.serialize(params) + '">Psychos in HH</a>');

关于javascript - grails 链接 - 将 javascript 变量添加到 params 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15479074/

相关文章:

javascript - 为什么所有东西都会多次发射?

javascript - 正则表达式:在每行的单个字符之前获取匹配项

javascript - 删除菜单标签

javascript - Three.js 部分拉伸(stretch)纹理

mongodb - 在 Grails 3.x 中安装和使用 MongoDB

javascript - 使用 git bash 错误设置 app.js

grails - 如何使用 Grails 可搜索插件将搜索限制为组件的字段值

grails - 在 IntelliJ 中使用 Grails 2.4.3

grails - 使用关系映射时,Grails通过id获取

grails - 先使用哪个,Grails 还是 Groovy?