简体   繁体   English

在服务器端Groovy页面中访问客户端jquery变量

[英]accessing client side jquery variable in server side groovy page

I have a variable in my JavaScript which contains the id of the clicked row in the master grid. 我的JavaScript中有一个变量,其中包含主网格中单击的行的ID。 I want to pass it to the groovy service page that handles my child grid so that it can filter the rows based on that id. 我想将其传递给处理我的子网格的groovy服务页面,以便它可以基于该id过滤行。 How do I do that? 我怎么做?

The problem is that your javascript-based grid runs on the client, while the page is rendered server-side. 问题是您的基于JavaScript的网格在客户端上运行,而页面在服务器端呈现。 Therefore, some communication must take place in order to instruct your application to filter rows based on what the user selects. 因此,必须进行一些通信以指示您的应用程序根据用户的选择来过滤行。

Grails uses the MVC architecture, this means that there is a controller that takes care of answering the requests generated from the client. Grails使用MVC架构,这意味着有一个控制器负责应答从客户端生成的请求。 To answer these requests, the Controller can make use of the Views (.gsp files). 为了回答这些请求,控制器可以使用视图(.gsp文件)。 So when you call to the URL controller/index you may make use of an index.gsp view to render your page. 因此,当您调用URL controller/index ,可以使用index.gsp视图来呈现页面。

What you need to do is to make an ajax call to a controller method (eg controller/getFilteredRows ) that gets as input the selected row (could be its id ) and based on some logic fetches all the required information and sends them back to the client encoded for example using JSON . 您需要做的是对控制器方法(例如controller/getFilteredRows )进行ajax调用 ,该方法获取所选行(可能是其id )作为输入,并基于某种逻辑获取所有必需的信息并将其发送回给客户端使用JSON编码。

Now the client knows the rows it has to display, hence you can update your grid. 现在,客户端知道必须显示的行,因此您可以更新网格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM