【问题标题】:How do you iterate over a map of lists using StringTemplate?如何使用 StringTemplate 遍历列表映射?
【发布时间】:2013-08-09 01:18:57
【问题描述】:

我需要生成如下所示的 HTML 输出:

 - 2010
    - Item 1
    - Item 2
 - 2011
    - Item 9
 - 2012
    - item 6

我尝试了一张地图,即Map<String,List<String>>,但我不知道你将如何迭代它,即这不起作用:

<ul class="chevron">
$x:{y|
    <li>$y$</li><ul class="chevron">
        $y:{z|<li>$z.name$/li>}$
    </ul>
}$
</ul>

【问题讨论】:

  • 字符串模板是语言
  • 哎呀。你每天都在学习……+1

标签: html stringtemplate


【解决方案1】:

在 YAML 表示法中,如果变量 x(Map&lt;String,List&lt;String&gt;&gt;) 类型)的内容是:

x:
  2010: [Item 1,Item 2]
  2011: [Item 9]
  2012: [Item 6]

以下内容将满足您的要求:

<ul>
$x.keys:{
k | <li>$k$</li>
  <ul>
    <li>$x.(k);separator="</li>
    <li>"$</li>
  </ul>
}$</ul>

注意$x.(k)$ 符号。

【讨论】:

    猜你喜欢
    • 2012-05-14
    • 1970-01-01
    • 2022-01-19
    • 2018-08-22
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多