Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterating over map in Freemarker [duplicate]

Tags:

freemarker

Possible Duplicate:
Freemarker iterating over hashmap keys

I have a Hash Map which contain item ids as a key and Item objects as a value. Following is the pseudo code -

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

On result.ftl I need to iterate over this map and get the values of Item Object. I have tried this approach but could not get values from Item object -

<#list item?keys as it>
    ${it} = ${item.get(it)[name]}
</#list>
like image 272
Saurabh Avatar asked Jun 29 '10 15:06

Saurabh


2 Answers

I think you want:

<#list allItems?keys as it>
  ${it} = ${allItems[it].name} 
</#list>
like image 91
jean Avatar answered Nov 05 '22 20:11

jean


<#assign seq=["a","b","c"]>
<#list seq as l>
  ${l[1]}
// It will print b
  ${l[0]}
//It will print a
</#list>
like image 40
user1312573 Avatar answered Nov 05 '22 22:11

user1312573