html5
  • grails
  • taglib
  • 2012-06-28 48 views 0 likes 
    0

    我是Grails平臺的新手,對TagLib組件感興趣。 我有這個應用程序,我將創建一個時間選擇[24小時制選擇],由兩個<select>標籤組成:小時和時間。到目前爲止,我以這種方式編寫了我的理論。Grails Taglib G:SELECT

    def timePicker = { attrs -> 
        out << "<g:select name='" + attrs['name'] + ".hour' from='${00..21}' />" 
        out << "<g:select name='" + attrs['name'] + ".minute' from='${00..59}' />" 
    } 
    

    但是我不能在頁面上顯示,但它顯示的out在網頁本身是錯誤的內容。 TagLib如何在.gsp上正確顯示兩個<select>?我打算將它寫入傳統的<select>伴隨着<option>語句,還是要使用g.select(attrs)語法?

    感謝

    回答

    2

    你可以使用這樣的事情:

    def timePicker = { attrs -> 
        def hours = 0..21 
        def stringHours = hours.collect{ String.format('%02d', it) } 
    
        def minutes = 0..59 
        def stringMinutes = minutes.collect{ String.format('%02d', it) } 
    
        out << "${select(from: stringHours, name: attrs.name + '.hour')}" 
        out << "${select(from: stringMinutes, name: attrs.name + '.minute')}" 
    } 
    
    1

    您只能在GSP使用一個方法調用:

    def timePicker = { attrs -> 
        out << "${select(from: 00..21, name: attrs.name + '.hour')}" 
        out << "${select(from: 00..59, name: attrs.name + '.minute')}" 
    } 
    
    +0

    謝謝。但有沒有一種方法來格式化單個數字[0-9],使其格式化爲兩位數字'0 \ d'?謝謝。 –

    相關問題