Freemarker list (length, traversal, subscript, nesting, sort)

Source: Internet
Author: User

1. Freemarker Gets the size of the list:

Java
Java code
    1. arraylist<string> list = new arraylist<string> ();

Freemaker
JavaScript code
    1. ${list?size}


2. List traversal:

JavaScript code
    1. < #list animals as being>
    2. <tr>
    3. <td>${being.name}${being.price}<td>
    4. </tr>
    5. </#list >


The subscript number in the 3.list traversal:

_index is a property of list
JavaScript code
    1. < #list list as a>
    2. ${a_index}
    3. </#list >


4. Nesting of list:
JavaScript code
    1. < #list jssklist as jsskvo>
    2. < #list kclist as kcvo>
    3. <#if kcvo.kch=jsskvo.kch> (KCVO with number and name, and JSSKVO only number)
    4. ${KCVO.KCM}
    5. </#if>
    6. </#list >
    7. </#list >


5. List sort:
Ascending. Sort_by ()
JavaScript code
    1. < #list list?sort_by ("field") as X>
    2. </#list >


Descending. Sort_by ()? reverse
JavaScript code
    1. < #list list?sort_by ("field")? reverse as X>
    2. </#list >


6. The list tag traverses the map:
JavaScript code
    1. < #list Avertisementtypemap?keys as key>
    2. <option value="${key}" >${avertisementTypeMap[key]}</option>
    3. </#list >
http://lauy.iteye.com/blog/1774917

Freemarker list (length, traversal, subscript, nesting, sort)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.