【问题标题】:How to Write Series in FreeMarker?如何在 FreeMarker 中编写系列?
【发布时间】:2021-12-11 04:41:18
【问题描述】:

我正在尝试用 Free-marker 编写数字和字母系列。但是我无法实现它。

我尝试了各种门户网站和 Freemarker 网站本身,但未能找到合适的解决方案。

【问题讨论】:

    标签: freemarker


    【解决方案1】:
       <#assign count = 0>
       <#assign seq = ['a','b','c','d','e','f',]>
       <#list params_list as test_param> 
           ${count}   ${seq[count]}
            <#assign count = count + 1> 
       </#list>
    

    它将打印数据

    1  a
    2  b
    3  c 
    

    【讨论】:

    • 这可以用?lower_abc?counter来简化;看我的回答。 (从 0 开始的项目索引可以通过 ?index 获得,但由于您实际上不需要 a-b-c 序列,因此这里不需要它。)
    【解决方案2】:

    您可以使用?lower_abc(或?upper_abc)将数字转换为字母,其中1 对应于字母“a”。如果这是在#list 内,那么您可以使用itemVariable?counter 获得基于1 的项目计数器。例如:

    <#list items as item> 
      ${item?counter} ${item?counter?lower_abc}
    </#list>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-14
      • 2022-10-14
      • 2022-07-17
      • 2012-09-15
      • 2022-10-15
      • 2012-06-09
      • 1970-01-01
      • 2021-10-23
      相关资源
      最近更新 更多