Quantcast

How we read the list<map;string>

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How we read the list<map;string>

Yadid Qin

Hello Freemarker Team,

 

There is one issue it confused me.

 

Eg: java code:

 

SimpleHash root = new SimpleHash();

List<Object> list = new ArrayList<Object>();

     list.add("red");

     list.add("green");

     list.add("blue");

     SimpleHash mapColor = new SimpleHash();

     mapColor.put("c1", "red");

     mapColor.put("c2", "green");

     mapColor.put("c3", "blue");

     list.add(mapColor);

root.put("theList", list);

 

FTL file:

<#list theList as item>

 

<#if item_index =3>    à if I do not know the index=3, then how I read the map in the list.

<#assign keys = item?keys>  

<#list keys as key>

${key} = ${item[key]}<br>

</#list>

<#else>

${item_index + 1}.  ${item}<br> 

</#if>

 

</#list>

 

Output:

+- theList
| |
+- 1. red
| |
+- 2. green
| |
+- 3. blue
| |
||
+- c1 = red
||
+- c2 = green
||
+- c3 = blue

 

 

Thanks & Best Regards,

Yadid

 

 

 


------------------------------------------------------------------------------
Time is money. Stop wasting it! Get your web API in 5 minutes.
www.restlet.com/download
http://p.sf.net/sfu/restlet
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How we read the list<map;string>

bredelet
Hi Yadid,

You can use is_hash_ex to find if the item is a map

http://freemarker.org/docs/ref_builtins_expert.html#ref_builtin_isType


From: "Yadid Qin" <[hidden email]>
To: "[hidden email]" <[hidden email]>
CC: "[hidden email]" <[hidden email]>
Sent: 28 May 2014 20:28
Subject: [FreeMarker-user] How we read the list

Hello Freemarker Team,

 

There is one issue it confused me.

 

Eg: java code:

 

SimpleHash root = new SimpleHash();

List<Object> list = new ArrayList<Object>();

     list.add("red");

     list.add("green");

     list.add("blue");

     SimpleHash mapColor = new SimpleHash();

     mapColor.put("c1", "red");

     mapColor.put("c2", "green");

     mapColor.put("c3", "blue");

     list.add(mapColor);

root.put("theList", list);

 

FTL file:

<#list theList as item>

 

<#if item_index =3>    à if I do not know the index=3, then how I read the map in the list.

<#assign keys = item?keys>  

<#list keys as key>

${key} = ${item[key]}<br>

</#list>

<#else>

${item_index + 1}.  ${item}<br> 

</#if>

 

</#list>

 

Output:

+- theList
| |
+- 1. red
| |
+- 2. green
| |
+- 3. blue
| |
||
+- c1 = red
||
+- c2 = green
||
+- c3 = blue

 

 

Thanks & Best Regards,

Yadid

 

 

 


------------------------------------------------------------------------------
Time is money. Stop wasting it! Get your web API in 5 minutes.
www.restlet.com/download
http://p.sf.net/sfu/restlet
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Loading...