2012-04-22 50 views
2

我想實現一個窗體,其中每個字段有多個選項,它必須是複選框的行。我想顯示這個表格,在行標題中的字段名稱和相應行中的複選框選項。我也需要數據庫表的實現方面的幫助。任何幫助將不勝感激。我是web2py的新手。提前致謝。Web2py - 多選項複選框實現

回答

0

你到目前爲止嘗試過什麼?這聽起來像你想與布爾值的數據模型:

(在模型/ ??? PY - 確保它db.py後執行,並且您已經定義了一個DB)

db.define_table('table_name', 
    Field('SomeFieldA', 'boolean') 
    Field('SomeFieldB', 'boolean') 
    Field('SomeFieldC', 'boolean') 
    Field('SomeFieldD', 'boolean') 
    ... etc ... 
) 

你可能不得不實現一個自定義表單來獲得你想要的佈局,因爲我想不出一種現成的方式來做到這一點。請參閱custom forms here

你需要開始是這樣的:

<table> 
{{=form.custom.begin}} 
    <thead> 
    <tr> 
    {{ #loop over form field labels... something like: 
     for field in form.fields: }} 
     <th>{{=field.label}}</th> 
    {{ pass }} 
    </tr> 
    </thead> 

    <tbody> 
    <tr> 
    {{for field in form.fields: }} 
     <td>{{ =form.custom.widget[field] }}</td> 
     {{ # or directly access it without a loop with form.custom.widget.SomeFieldA }} 
    {{ pass }} 
    </tr> 
    </tbody>  

    {{=form.custom.submit}} 
{{=form.custom.end}} 
</table> 

請注意,我沒有測試過此代碼的任何,我可能訪問表單字段和標籤不正確。如果您需要預先填寫表格,請在控制器中進行。上面的自定義表單鏈接也討論了預填充。