freemarker循環、下標及判斷


一、freemarker中list循環使用非常頻繁,下面介紹lfreemarker中list簡單的用法

  1、在freemarker中遍歷list數組使用list指令:<#list sequence as item>...</#list>;

  其中sequence為集合(controller)的表達式,item是循環變量名(別名),不可是表達式;

  在遍歷sequence的時候會將sequence中的變量或者對象放到item中,后面使用時只需用item即可;

  例如:<#list libraryVOs as libraryVO>

  注: libraryVOs集合為標簽集合,GroupDTO為標簽組 

  libraryVOs為sequence表達式,libraryVO為item變量;libraryVOS中有多個GroupDTO對象,在遍歷時會將GroupDTO存放到libraryVO中。如果取GroupDTO中的名稱

  使用${libraryVO.applyName};

  2、item_index:當前迭代項在所有迭代項中的位置,是數字值。

  3、freemarker判斷<#if (x>y)></#if> 注:要使用括號括起來

  

<ul>
    <#list libraryVOs as libraryVO>
        <li>
            <span class="content-l-title">${libraryVO.groupDto.applyName}(${libraryVO.count}):</span>
            <ul class="content-l-content">
                <#list libraryVO.labelDto as labelLibrary>
                    <#if (labelLibrary_index <= 3)>
                        <li>
                            <span class="second-title">${labelLibrary.applyName}:</span>
                            <span class='second-title hide' id='labelId${labelLibrary.autoId}'>${labelLibrary.applyName}</span>
                            <label for="checkbox10" class="checkbox${labelLibrary.autoId}0" onclick="getLabelCustom(${labelLibrary.autoId})">
                                <input type="radio" id="checkbox0${labelLibrary.autoId}" value="1" name="tag1">
                                <b><img src="${resRoot}/css/images/xianze.png" alt=""></b>
                                    自定義
                            </label>
                            <label for="checkbox11" class="checkbox${labelLibrary.autoId}1" onclick="getLabelAll(${labelLibrary.autoId})">
                                <input type="radio" id="checkbox1${labelLibrary.autoId}" value="0" name="tag1">
                                <b><img src="${resRoot}/css/images/xianze.png" alt=""></b>
                                    不限
                            </label>
                            <input id="tagSel${labelLibrary.autoId}" name="tagSel${labelLibrary.autoId}" onclick="showTag(${labelLibrary.autoId}); return false;" class="tag-item ${labelLibrary.autoId} hide" type="text" readonly value="">
                            <input id="tagSelId${labelLibrary.autoId}" name="tagSelId${labelLibrary.autoId}" type="hidden" value="" style="width:120px;">
                            <div id="tagContent${labelLibrary.autoId}" class="tagContent${labelLibrary.autoId}" style="position: absolute; left: 64px; display:none;width:160px;height:200px;overflow-y:scroll;overflow-x:auto;z-index:5555;background: #fff;">
                                <ul id="tagDemo${labelLibrary.autoId}" class="ztree"></ul>
                            </div>
                        </li>
                    </#if>
                    
                    <#if (labelLibrary_index > 3)>
                        <li class="list hide">
                             <span class="second-title">${labelLibrary.applyName}:</span>
                            <span class='second-title hide' id='labelId${labelLibrary.autoId}'>${labelLibrary.applyName}</span>
                            <label for="checkbox10" class="checkbox${labelLibrary.autoId}0" onclick="getLabelCustom(${labelLibrary.autoId})">
                                <input type="radio" id="checkbox0${labelLibrary.autoId}" value="1" name="tag1">
                                <b><img src="${resRoot}/css/images/xianze.png" alt=""></b>
                                    自定義
                            </label>
                            <label for="checkbox11" class="checkbox${labelLibrary.autoId}1" onclick="getLabelAll(${labelLibrary.autoId})">
                                <input type="radio" id="checkbox1${labelLibrary.autoId}" value="0" name="tag1">
                                <b><img src="${resRoot}/css/images/xianze.png" alt=""></b>
                                    不限
                            </label>
                            <input id="tagSel${labelLibrary.autoId}" name="tagSel${labelLibrary.autoId}" onclick="showTag(${labelLibrary.autoId}); return false;" class="tag-item ${labelLibrary.autoId} hide" type="text" readonly value="">
                            <input id="tagSelId${labelLibrary.autoId}" name="tagSelId" type="hidden" value="" style="width:120px;">
                            <div id="tagContent${labelLibrary.autoId}" class="tagContent${labelLibrary.autoId}" style="position: absolute; left: 64px; display:none;width:160px;height:200px;overflow-y:scroll;overflow-x:auto;z-index:5555;background: #fff;">
                                <ul id="tagDemo${labelLibrary.autoId}" class="ztree"></ul>
                            </div>
                        </li>
                    </#if>
                 </#list>
                 <#if (libraryVO.labelDto?size > 3)>
                     <li>
                        <span class="l-more">更多<i class="more-icon"></i></span>
                        <span class="l-close hide">收起<i class="close-icon"></i></span>
                    </li>
                </#if>
            </ul>
        </li>
    </#list>        
</ul>

 

  

  

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM