freemarker循環、下標及判斷

1、freemarker中list循環使用很是頻繁,下面介紹lfreemarker中list簡單的用法css

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

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

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

  例如:<#list libraryVOs as libraryVO>spa

  注: libraryVOs集合爲標籤集合,GroupDTO爲標籤組 code

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

  使用${libraryVO.applyName};blog

  二、item_index:當前迭代項在全部迭代項中的位置,是數字值。get

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

  

<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>
相關文章
相關標籤/搜索