简体   繁体   English

s:带有动态键参数的Map上的迭代器

[英]s:iterator over Map with a dynamic key parameter

I have a problem with the inner iterator in the following Struts2 JSP: 我在下面的Struts2 JSP中遇到了内部迭代器的问题:

<s:iterator value="thatCompany.tags" var="tagGroups">
  <tr>
     <td><s:property value="#tagGroups.key" /></td><!-- this works nicely! -->
     <td>
    <ul>
     <s:iterator value="{thisCompany.tags['#tagGroups.key']}" var="thisTagGroup">
           <!-- doesn't work, displays one empty LI element -->
           <li> <s:property value="#thisTagGroup.key"/>
      </s:iterator>
    </ul>
      </td>
<!-- snip -->

thisCompany.tags and thatCompany.tags are both of type Map<String, Map<BigDecimal, String>> thisCompany.tagsthatCompany.tags都是Map<String, Map<BigDecimal, String>>

Got it, this syntax works: 知道了,这个语法有效:

<s:iterator value="thisCompany.tags[#tagGroups.key]" var="foobar">
  <li> <s:property value="#foobar.value"/>
</s:iterator>

But this is weird: if I name the variable thisTagGroup instead of foobar it doesn't work anymore. 但这很奇怪:如果我将变量命名为thisTagGroup而不是foob​​ar,它就不再起作用了。 Is it because this is somehow reserved and variable names cannot even begin with this- ? 难道是因为是莫名其妙地保留和变量名,甚至不能用这个-开始呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM