2011-12-13 60 views
0

这段代码有什么问题,因为即时获取所有结果返回到视图,这需要我加载太多。我希望它每页只返回5个。Grails paginate用法

控制器:

{ 

    def channel2 = Channel2.list(params) 
    //def prog = Programmation.list() 
    def prog 
    def progs = [:] 
    def temp 

    channel2.each{ 
     Programmation p = Programmation.withCriteria { 
      eq('prog_channel', it) 
      'between'('prog_start', new Date(), new Date() +1)  
     } 
     progs.put(it.id, p) 
    } 

    [channel: channel2, program: progs] 

} 

GSP

<g:render id="" template="/layouts/canais"/> 

<g:paginate next="Forward" prev="Back" 
     maxsteps="0" max="3" controller="teste" 
     action="myProgramms_canais" 
     total="${tv_megazineplus.Channel2.count()}" /> 

我上无法弄明白。我跟着Grails helpPage,它应该工作。

+0

对此有何帮助?仍然没有工作 – recoInrelax

回答

0

解决方案:第一次的行动被调用,因为params.max设置为null,它加载的所有通道。要解决这个问题,只需使用:

def offset 

     if(!params.offset){ 
      offset = 0 
     } 

     def channel2 = Channel2.list(max:5, offset: offset)