【发布时间】:2014-06-26 10:48:05
【问题描述】:
我需要显示一系列复选框,如果条件成功,我需要选中它们。下面是我的代码。我有一个 hashmap 的区域和一个数组列表的 SelectedRegions。我正在遍历我的区域地图,并在其旁边显示带有文本的复选框作为我的区域地图中的值。现在,在迭代时,如果区域映射的值在数组列表中可用,我需要选中该复选框。否则取消选中。我尝试了如下所示的。但它不起作用。
<s:iterator value="regions">
<li>
<div class="listClass">
<s:if test="#regions.value==selectedRegions.value">
<input type="checkbox" id='myTheater' checked="checked" name="theaterCheckBox" class="theaterCheckBox" />
<s:property value="value" />
</s:if>
<s:else>
<input type="checkbox" id='myTheater' name="theaterCheckBox" class="theaterCheckBox" />
<s:property value="value" />
</s:else>
</div>
<div class="checkboxDiv">
<input type="checkbox" id="allFeatured" class="featuredCheckBox" />
</div>
</li>
</s:iterator>
某种程度上,我使用的 if 条件不起作用。能不能请你 让我知道如何做到这一点?
【问题讨论】:
-
有什么理由不使用 struts2 标签作为输入?还有,我没用过struts2,但不应该是
#{condition}而不是#condition吗? -
@AnthonyGrist:绝对不是
#{...}。 user1321648:你会在课堂上怎么做? -
我没有使用 struts 标签,因为它不允许我进行自定义。我需要并排显示一个带有两个复选框的下拉菜单。我无法通过使用 struts 2 输入标签来实现这一点。
-
我也尝试使用条件 -
但它没有用。 -
@aleksandr M:在我的课堂上,我会说 for (Map.Entry
entry : map.entrySet()) { if(myList.contains(entry.getValue())) // ... }