9

我正在尝试遍历哈希图并显示一个数字复选框,其中 id 是哈希图的键,并标记哈希图的值。任何人都知道挂毯的语法是怎样的?

干杯迪米特里斯

4

1 回答 1

14

您应该能够像这样遍历密钥集:

<form t:type="Form">
    <t:Loop t:source="myMap.keySet()" t:value="currentKey"> 
        <input type="Checkbox" t:type="Checkbox" t:id="checkbox"
            t:value="currentValue"/>
        <label t:type="Label" for="checkbox">${mapValue}</label>
    </t:Loop>
</form>

类文件:

@Property
private Object currentKey;

@Persist
private Set<String> selection = new HashSet<String>();

public Map<String,String> getMyMap() {
    ...
}

public boolean getCurrentValue() {
     return this.selection.contains(this.currentKey);
}

public void setCurrentValue(final boolean currentValue) {
    final String mapValue = this.getMapValue();

    if (currentValue) {
        this.selection.add(mapValue);
    } else {
        this.selection.remove(mapValue);
    }
}


public String getMapValue() {
    return this.getMyMap().get(this.currentKey);
}

我还没有编译这个,但它应该可以帮助你开始。

于 2010-03-12T18:45:46.497 回答