【问题标题】:Grails: Using javascript to display results in same viewGrails:使用 javascript 在同一视图中显示结果
【发布时间】:2012-07-03 22:36:19
【问题描述】:

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

我想要做的是结合这两个页面,以便用户停留在一个页面上。

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

...  
<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 专家,那么我该如何处理这个结果列表呢?我已经尝试了六种不同的东西并且被难住了。我有一个部分 resulttable 我想在其中显示结果。还是我用这种方法在左外野?

【问题讨论】:

    标签: jquery grails


    【解决方案1】:

    我认为您不一定需要直接使用 jQuery 来执行此操作。你可以像这样设置你的 gsp:

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

    然后在你的控制器中 doit 操作:

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

    【讨论】:

    • 我不知道我做错了什么,但这对我昨天不起作用。再次解决了这个问题,它奏效了 - 是的!
    猜你喜欢
    • 2015-07-13
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多