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

时间:2013-03-18 14:20:33

标签: 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(); 

1 个答案:

答案 0 :(得分:4)

<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>');