Grails RemoteFunction params语法 [英] Grails RemoteFunction params syntax

查看:66
本文介绍了Grails RemoteFunction params语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在grails中传递一些参数给remoteFunction,但我正在努力正确格式化它。

我想传递值一页页面上的数据加上我刚刚标签出来的文本框的值,所以在我的onblur中我有一些内容:

 的onblur = $ {remoteFunction(动作: '戴夫',更新: '包' + it.id,
PARAMS:[DENOM:的document.getElementById(denomValue + $ {it.id} ).value,
amount:this.value])}

这不会编译 - 我可以用不同数量的单引号和转义字符组成任何排列组合。



我认为真正困扰我的是我没有真正理解我想在这里创造什么。这是否像使用JSP代码创建后续将执行的JavaScript?什么时候这个表达式被评估 - 它是在页面被编译的时候 - 或者是在它被调用的时候是= a吗?



任何帮助我们都非常感谢。

解决方案



Grails代码将在页面构建发送到客户端浏览器时进行评估。

Javascript代码将会评估一次该页面已被传递到浏览器。



考虑到这一点,让我们看看你的onblur作业:

  onblur = $ {remoteFunction(
action:'dave',
update:'pack'+ it.id,
params:[ denom:document.getElementById(denomValue + $ {it.id})。value,
amount:this.value])}

鉴于$ {remoteFunction ...}调用是一个Grails标记,它将在服务器上进行评估,生成一个修复程序d字符串,然后发送给客户端。



看看params地图,你已经在denom值中添加了一些Javascript,里面 Groovy代码:

  document.getElementById(denomValue 

然后您尝试从Groovy添加一个值

  + $ {it。 id} 

然后再一次使用Javascript

)。

Groovy编译器会尝试评估Javascript作为Groovy代码并失败。



如果您需要访问Javascript中的客户端参数,您需要自己处理Javascript(并且不使用remoteFunction标记),例如来处理远程调用:

  var path = $ {createLink(action:'dave',
params :[amount:this.value])}
+& denom =
+ document.getElementById(denomValue + $ {it.id})。value

您还需要使用Javascript自行处理远程响应以更新'pack'元素。您可以随时查看remoteFunction调用产生的内容,将其复制到页面中并进行编辑以实现您想要的功能。



HTH


I'm trying to pass a couple of parameters to a remoteFunction in grails but I'm struggling to format it correctly

I want to pass in the value of a piece of data on the page plus the value of the text box that I have just tabbed out of, so in my onblur I have something along the lines of :

onblur=${remoteFunction(action:'dave',  update:'pack'+it.id,
         params:[denom:document.getElementById(denomValue+${it.id}).value ,
         amount:this.value ])}

This doesn't compile - neither do any permutations I can come up with with varying numbers of single quotes and escape characters ..

I think what is really stumping me is thatI don;t really understand what I am trying to create here. Is it like using JSP code to create JavaScript which iwill be later executed? When does this expression get evaluated - it is at the time the page is compiled - or is a=it at the time that oblur gets called?

Any help greatly appreciated.

解决方案

It looks like you've mixed up server-side code with client-side code.

The Grails code will be evaluated when the page is being "built" to be sent to the client browser.

The Javascript code will be evaluated once the page has been delivered to the browser.

With this in mind let's take a look at your onblur assignment:

onblur=${remoteFunction(
         action:'dave', 
         update:'pack'+it.id, 
         params: [denom: document.getElementById(denomValue+${it.id}).value, 
                  amount: this.value ])}

Given the ${remoteFunction...} call is a Grails tag, it will be evaluated on the server, generate a fixed string, then be sent to the client. Everything inside the call must be valid Groovy code.

Look at the params map, you've added some Javascript in the denom value, inside the Groovy code:

document.getElementById(denomValue

then you try to add a value from Groovy

+${it.id}

then some Javascript again

).value

The Groovy compiler will try to evaluate the Javascript as Groovy code and fail.

If you need to access client-side parameters in Javascript you'll need to handle the Javascript yourself (and not use the remoteFunction tag), for example to handle the remote call:

var path=${createLink(action:'dave',
                      params: [amount:this.value])} 
           + "&denom=" 
           + document.getElementById(denomValue+${it.id}).value

You'll also need to handle the remote response yourself using Javascript to update the 'pack' elements. You could always look at what the remoteFunction call generates, copy it into the page and edit it to do what you want.

HTH

这篇关于Grails RemoteFunction params语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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