填充 Freemarker 模板上的组合框

Fill a combobox that is on Freemarker template

我正在尝试将数据加载到组合框上,该组合框存储在名为 columnList<ArrayList<String>> 中。

这是我的模板收费数据代码:

List<ArrayList<String>> columna = con.getColumn("table", "column");
Iterator<ArrayList<String>> iter = columna.iterator();
String name= null;
while (iter.hasNext()) {
    ArrayList<String> row = iter.next();
    for(int i=0; i<row.size(); i++) {
        name=row.get(i);
        attributes.put("tmplattribute", name); //There are my problem I think
    }
}

getRow() 方法从 db 和行项目存储值 column 获取数据。

在我的模板中,组合框代码是:

<p>Choose one: 
    <select name="combo">
        <option value="" disabled="disabled" selected="selected"> </option>
        <option value="${tmplattribute}">${tmplattibute}</option>
    </select>
</p>

有没有办法用所有数据填充该组合框?目前我只得到最后一行,因为 'attributes' 参数是一个(键,值)数据,我只能为该键存储一个值。

List<ArrayList<String>> columna = con.getColumn("table", "column");
attributes.put("mylist", columna);

然后在您的 freemarker 模板中

<#list mylist as it>
    <select name="combo">
        <#list it as tmplattribute>
            <option value="${tmplattribute}">${tmplattribute}</option>
        </#list>
    </select>
</#list>

Here 你可以查看 freemarker 文档。

谢谢大牛!你的回答告诉我解决问题的方法,

如果我使用您的模板代码,我会从列表中获得每个对象的组合框,但如果我像这样更改顺序:

<select name="combo">
    <#list mylist as it>
        <#list it as tmplattribute>
            <option value="${tmplattribute}">${tmplattribute}</option>
        </#list>
    </#list>
</select>

我得到我所需要的。再次感谢您,因为您的回答为我指明了方向。