8

可能重复:
Freemarker 迭代 hashmap 键

我有一个哈希映射,其中包含作为键的项目 ID 和作为值的项目对象。以下是伪代码 -

allItems : {
  12: itemObj1 (id:12, name:myitem1)
  13: itemObj2 (id:13, name:myitem2)
  14: itemObj3 (id:14, name:myitem3)
}

在 result.ftl 上,我需要遍历此地图并获取项目对象的值。我已经尝试过这种方法,但无法从 Item 对象中获取值 -

<#list item?keys as it>
    ${it} = ${item.get(it)[name]}
</#list>
4

2 回答 2

10

I think you want:

<#list allItems?keys as it>
  ${it} = ${allItems[it].name} 
</#list>
于 2010-08-19T15:22:57.060 回答
1
<#assign seq=["a","b","c"]>
<#list seq as l>
  ${l[1]}
// It will print b
  ${l[0]}
//It will print a
</#list>
于 2012-04-04T10:27:42.323 回答