Grails:使用javascript在同一视图中显示结果 [英] Grails: Using javascript to display results in same view

查看:107
本文介绍了Grails:使用javascript在同一视图中显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个域(模型)工作和结果。
作业页面列出已经运行的作业,结果页面列出作业结果。

I have two domains (models) Job and Results. The Job page that lists jobs that have run and the Results page lists the results of the job.

我想要做的是将这两页合并用户停留在一页上。

What I want to do is combine these two pages so that the user stays on the one page.

我的解决方案是使用remoteFunction,而且我很接近,但我一直在从Grails获取数据。下面的代码调用我的控制器(方法 doit ),并返回一个Groovy列表:

My solution was to use remoteFunction, and I am close but am stuck on getting the data back from Grails. The code below calls my controller (method doit) and it returns a Groovy List:

...  
<g:render template="resulttable" />
<button id=show>show()</button>
<script type="text/javascript">
$("#show").click(function () {
  // Returns Groovy List
  var results = <g:remoteFunction action="doit" id="${idx}" update="showit"/>  
  $(".resulttable").show('slow');
});

我不是jQuery的高手,那么如何处理这个结果列表呢?我已经尝试了六种不同的东西,我很难过。我有一部分结果表,我想在结果中显示结果。或者我用这种方法出现在左边区域?

I am not a whiz with jQuery, so how do I process this results list? I have tried a half dozen different things and am stumped. I have a partial resulttable where I want to dislay the results. Or am I out in left field with this approach?

推荐答案

我不认为你一定需要直接使用jQuery来做这个。您可以像这样设置您的gsp:

I don't think you necessarily need to use jQuery directly to do this. You could set up your gsp like this:

<g:remoteLink action="doit" id="${idx}" update="showit"><button>show()</button></g:remoteLink>
<div id="showit">
</div>

然后在你的控制器中 doit action :

And then in your controller you doit action:

def doit = {
    //find your list here
    def yourList = ...
    render(template: "resulttable", model: [listInTemplate: yourList])
}

这篇关于Grails:使用javascript在同一视图中显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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