freemarker递归显示树形列表

之前在网上参考了几个,都不对,想了下,ok,结果如下:
<#macro buildNode childs>
    <#if childs?? && childs?size gt 0>
        <#list childs as child>
        	<option value="${child.model.id}" label="<#list 1..depth as i>&nbsp;&nbsp;&nbsp;&nbsp;</#list>${(child.model.typeName)?if_exists}">
        		<#list 1..depth as i>&nbsp;&nbsp;&nbsp;&nbsp;</#list>${(child.model.typeName)?if_exists}
        	</option>
            <#assign depth = depth + 1 />
            <@buildNode childs=child.childs />
            <#assign depth = depth - 1 />
        </#list>
    </#if>
</#macro>


				<#assign depth = 1 />
				<select name="model.typeId">
				<#list typeList as typeDomain>
					<option value="${typeDomain.model.id}" label="${(typeDomain.model.typeName)?if_exists}">
						${(typeDomain.model.typeName)?if_exists}
					</option>
        			<@buildNode childs=typeDomain.childs />
				</#list>
				</select>

你可能感兴趣的:(递归,macro)