0

我是 grails 新手,刚刚开始在工作中开发应用程序。我想做的第一件事是创建一个带有两个表的 gsp,每个表都具有分页功能。通过研究,我发现有一个名为 remotePagination 的插件,它使用 ajax 来更新表格分页。我遇到的问题是“params.max”和“params.offset”值是两个字符串的映射,而不仅仅是一个字符串值。在打开页面时,会调用“列表”闭包,并为最大值和偏移量设置正确的值,比如 10。在第二次调用时,当调用 ajax 闭包时,最大值和偏移量值分别保存在地图中如下:

params.max = [10,10]
params.offset = [10,10]

我正在使用的代码如下:

控制器:

def list = {
    params.max = Math.min(params.int('max') ?: 10, 100)
    [bookInstanceList: Book.list(params), bookInstanceTotal: Book.count()]
}

def ajaxListBooks = {
    params.max = Math.min(params.int('max') ?: 10, 100)
    render(template: "bookList", model:[bookInstanceList: Book.list(params), bookInstanceTotal: Book.count()])
}

列表.gsp

<%@ page import="com.intelligrape.Book" %>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="layout" content="main"/>
  <g:set var="entityName" value="${message(code: 'book.label', default: 'Book')}"/>
  <title><g:message code="default.list.label" args="[entityName]"/></title>
  <g:javascript library="prototype"/>
 </head>

 <body>
   <div class="nav">
     <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a>
    </span>
    <span class="menuButton"><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]"/></g:link></span>
   </div>

   <div class="body">
     <h1><g:message code="default.list.label" args="[entityName]"/></h1>
     <g:if test="${flash.message}">
       <div class="message">${flash.message}</div>
     </g:if>
   <div id="repoList">
            <g:render template="bookList"/>
   </div>
   </div>
 </body>
</html>

_listBooks.gsp

<%@ page import="com.nmi.uk.sw.subzero.Book" %>

<div>
  <table>
    <thead>
    <tr>

        <util:remoteSortableColumn property="author" title="${message(code: 'book.author.label', default: 'Author')}" update="repoList" action="ajaxListBooks"/>
        <util:remoteSortableColumn property="name" title="${message(code: 'book.name.label', default: 'Name')}" update="repoList" action="ajaxListBooks"/>
        <util:remoteSortableColumn property="price" title="${message(code: 'book.price.label', default: 'Price')}" update="repoList" action="ajaxListBooks"/>

    </tr>
    </thead>
    <tbody>
    <g:each in="${bookInstanceList}" status="i" var="bookInstance">
        <tr class="${(i % 2) == 0 ? 'even' : 'odd'}">

            <td><g:link action="show" id="${bookInstance.id}">${fieldValue(bean: bookInstance, field: "author")}</g:link></td>

            <td>${fieldValue(bean: bookInstance, field: "name")}</td>

            <td>${fieldValue(bean: bookInstance, field: "price")}</td>

        </tr>
    </g:each>
    </tbody>
</table>
<div class="paginateButtons">
    <util:remotePaginate total="${bookInstanceTotal}" update="repoList"
                                      action="ajaxListBooks"
                                      pageSizes="[10,20,30,40,50,60,70,80,90,100]" />
</div>
</div>

上面的代码基于 remotePagination 教程的示例应用程序。它没有那么不同。我创建它只是为了在将插件集成到我的应用程序之前查看插件是否可以工作。

我想知道是否有其他人遇到过这个问题以及是否有解决方案。非常感谢。

4

1 回答 1

0

在您的 中,标签_bookList.gsp中有错误:<util:remotePaginate

pageSizes="[10,20,30,40,50,60,70,80,90,100]"

pageSizes应该是地图,而不是列表,例如:

pageSizes="[10:'10 Per Page', 20: '20 Per Page', 50:'50 Per Page',100:'100 Per Page']"
于 2013-01-04T19:42:52.237 回答