如何将struts2中的迭代器列表传递给javascript?

时间:2016-02-15 08:12:51

标签: javascript jsp struts2 ognl struts-tags

<fieldset class="fieldset">
  <legend class="legendtitle">DEDUCTIONS</legend>
  <table width="100%"  border="0" cellspacing= "0" cellpadding="0">
    <tr>
      <td class="Htd_one1" width="20%"><div align="center">Component</div></td>
      <td class="Htd_one1" width="20%"><div align="center">Allocated</div></td>
    </tr>

    <s:iterator value="%{#resultLists.deductionLists}" id="hrEmpSalaryCompDeductionList" 
                                                   status="stat">
      <s:if test="%{#allowanceList.allocatedSalAmount > 0}">
        <tr>
          <td class="labelone1" >
            <div align="center">
              <s:property value="%{#allowanceList.componentDesc}" />
            </div>
          </td>
          <td class="dataone1" >
            <div align="right"> 
              <s:property value="%{#allowanceList.allocatedSalAmount}" />
            </div>
          </td>
        </tr>
      </s:if>
    </s:iterator>
  </table>
</fieldset>

如果迭代器列表allowanceList.allocatedSalAmountresultLists.deductionLists的值都不大于0,我需要隐藏整个字段集。

我想调用javascript并传递resultLists.deductionLists的值,然后设置一个计数器,如果任何allocatedSalAmount大于0。

但是如何将resultLists.deductionLists的列表值传递给javascript?并且可以访问所有allowanceList.allocatedSalAmount吗?

1 个答案:

答案 0 :(得分:0)

要隐藏整个fieldset,您必须使用s:if标记对其进行包装。

<s:if test="%{#allowanceList.allocatedSalAmount > 0}">
<fieldset class="fieldset">
  <legend class="legendtitle">DEDUCTIONS</legend>
  <table width="100%"  border="0" cellspacing= "0" cellpadding="0">
    <tr>
       <td class="Htd_one1" width="20%"><div align="center">Component</div></td>
       <td class="Htd_one1" width="20%"><div align="center">Allocated</div></td>
       </tr>

    <s:iterator value="%{#resultLists.deductionLists}" id="hrEmpSalaryCompDeductionList" 
                                                   status="stat">

        <tr>
          <td class="labelone1" >
            <div align="center">
              <s:property value="%{#allowanceList.componentDesc}" />
            </div>
          </td>
          <td class="dataone1" >
            <div align="right"> 
              <s:property value="%{#allowanceList.allocatedSalAmount}" />
            </div>
          </td>
        </tr>

    </s:iterator>
  </table>
</fieldset>
</s:if>

因为您可以在fieldset中一次只迭代一个列表,所以不能让两个列表都由同一个迭代器迭代。您必须在s:if标记中定义要评估的正确表达式,以决定是否应显示fieldset。