2014-04-04 118 views
0

以下是我通過數據庫中的設備表創建的列表。我正在使用表格打印它。對於每一行我想添加複選框。我到底該怎麼做?將複選框添加到grails中的列表中

  <table> 
        <thead> 


        <tr> 

         <g:sortableColumn property="dname" title="${message(code: 'devices.dname.label', default: 'Dname')}" /> 

         <g:sortableColumn property="owner" title="${message(code: 'devices.owner.label', default: 'Owner')}" /> 

         <g:sortableColumn property="serailNumber" title="${message(code: 'devices.serailNumber.label', default: 'Serail Number')}" /> 

         <g:sortableColumn property="supportingAndroidVersion" title="${message(code: 'devices.supportingAndroidVersion.label', default: 'Supporting Android Version')}" /> 

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

         <td>${fieldValue(bean: devicesInstance, field: "dname")}</td> 

         <td>${fieldValue(bean: devicesInstance, field: "owner")}</td> 

         <td>${fieldValue(bean: devicesInstance, field: "serailNumber")}</td> 

         <td>${fieldValue(bean: devicesInstance, field: "supportingAndroidVersion")}</td> 

        </tr> 
       </g:each> 
       </tbody> 
      </table> 

回答

1
<table> 
        <thead> 


        <tr> 
         <td></td> 
         <g:sortableColumn property="dname" title="${message(code: 'devices.dname.label', default: 'Dname')}" /> 

         <g:sortableColumn property="owner" title="${message(code: 'devices.owner.label', default: 'Owner')}" /> 

         <g:sortableColumn property="serailNumber" title="${message(code: 'devices.serailNumber.label', default: 'Serail Number')}" /> 

         <g:sortableColumn property="supportingAndroidVersion" title="${message(code: 'devices.supportingAndroidVersion.label', default: 'Supporting Android Version')}" /> 

        </tr> 
       </thead> 
       <tbody> 
       <g:each in="${Devices.list()}" status="i" var="devicesInstance"> 
        <tr class="${(i % 2) == 0 ? 'even' : 'odd'}"> 
         <td><g:checkbox name="myCheckbox${i}" value="${true}"/></td> 
         <td>${fieldValue(bean: devicesInstance, field: "dname")}</td> 

         <td>${fieldValue(bean: devicesInstance, field: "owner")}</td> 

         <td>${fieldValue(bean: devicesInstance, field: "serailNumber")}</td> 

         <td>${fieldValue(bean: devicesInstance, field: "supportingAndroidVersion")}</td> 

        </tr> 
       </g:each> 
       </tbody> 
      </table> 
+0

,但你給起的複選框myCheckbox的名稱。然後,表格每一行中的複選框名稱將爲mycheckbox。對? – Sag

+1

是的,這只是一個例子,我做了一些更正,由於您的意見,請檢查... – emilan

+0

我得到的是以下錯誤'標記[複選框]不存在。找不到名稱空間的標籤庫:g' – Sag

相關問題