2011-12-13 59 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)