【问题标题】:How to pass iterator list in Struts 2 to JavaScript?如何将 Struts 2 中的迭代器列表传递给 JavaScript?
【发布时间】:2016-05-26 01:35:06
【问题描述】:
<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>

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

我想调用 JavaScript 并传递 resultLists.deductionLists 的值,然后在 allowanceList.allocatedSalAmount 大于 0 时设置一个计数器。

但是如何将resultLists.deductionLists 的列表值传递给JavaScript 并从中访问所有allowanceList.allocatedSalAmount

【问题讨论】:

  • 什么是allowanceList?它在哪里 ?您是否有一个 List of Lists 和另一个名为 permitList 的并行 List ?或者它是一个 List of Lists 列表?你的结构不清楚,我知道如何解决你的问题,但要写一个更具体的答案,我宁愿有结构

标签: javascript jsp struts2 ognl struts-tags


【解决方案1】:

要隐藏整个fieldset,你必须用&lt;s:if&gt;标签包裹它。

<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>

因为您一次只能在字段集中迭代一个列表,所以不能让两个列表都由同一个迭代器进行迭代。您必须定义正确的表达式以在 &lt;s:if&gt; 标记中进行评估,以决定是否应显示字段集。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-17
    • 2016-05-15
    • 2015-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多