سؤال

أحاول حلقة من خلال Hashmap وعرض مربعات اختيار رقم مع معرف مفتاح Hashmap وتسمي قيمة Hashmap. أي شخص يعرف كيف هو بناء بناء الجملة لهذا هو؟

هتاف ديميتريس

هل كانت مفيدة؟

المحلول

يجب أن تكون قادرا على حلقة من خلال مجموعة المفاتيح مثل هذا:

<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);
}

لم أستلم هذا، لكن يجب أن يساعدك في البدء.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top