该 Controller 将列出我数据库中的所有游戏。
def index() {
def platform = gameService.listPlatform()
def max = params.max ?: 10
def offset = params.offset ?: 0
def chosenPlatfrm = params.platform
def taskList = gameService.listGamePlat(chosenPlatfrm,max,offset)
def taskL = gameService.whatsHot(chosenPlatfrm,max,offset)
[games:taskL, bb:taskList, chosenPlatform:chosenPlatfrm, platforms:platform, gameCount:taskL.totalCount, gameCont:taskList.totalCount]
}
这就是我的index.gsp的样子。
<g:each in="${games}" status="i" var="game">
<g:if test="${game.averageRating != 0 }">
<g:link action="gameProfile"
params="${[gameTitle: "${game.gameTitle}"]}">
</g:link>
</g:if>
</g:each>
<div class="pagination" style="text-align: center;">
<g:paginate action="index" total="${gameCount}" offset="0" max="3" params="${params.max}"/>
</div>
我想将分页 View 限制为每页仅3个项目。当index.gsp从我的索引 Controller 接收数据时,即使我有一个分页标签,它也会显示列表中的所有内容,但是当我单击一个页码时,它似乎运行良好。
我在索引 Controller 中尝试重定向,但显示错误“错误重定向循环”
redirect(action: "index", params:[id:'',offset: '0', max: '3'])
如何正确显示index.gsp?
最佳答案
我认为存在一个问题。尝试:
<g:paginate total="${gameCount}" />
代替:
<g:paginate action="index" total="${gameCount}" offset="0" max="3" params="${params.max}"/>
Controller 中的另一个问题是:您应该编写另一个函数来计算 gameCount 变量,该变量将计算每个分页 View 中所有游戏的数量(因此不包含offset和limit参数)。
当然,重定向是错误的,因为您要一遍又一遍地执行 Controller 的index()函数,因此请保留第一个提供的代码。
关于grails - 如何在我的分页 View 中正确显示列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34913584/