用freemarker定義宏實現自定義公用控件

參考文章:javascript

Freemarker自定義標籤的簡單分析  html

定義一個基本的文本框:傳入參數爲:resourceName idName resourceVal="" idVal="" classVal="",其中resourceName ,idName爲必填, resourceVal="" idVal="" classVal="" 分別爲選填,其中必填都做爲空間的 name,選填的都做爲結果值,具體的見代碼:java

html中 macro自定義以下:node

<#macro txtResource resourceName idName  resourceVal="" idVal="" classVal="">
    <input type="text" name="${resourceName}" value="${(resourceVal)!}" class="${(classVal)!}" readonly="readonly" 
style
="cursor:pointer" /> &nbsp;<a class="xm_ablue" href="javascript:clearDicTree('${resourceName}','${idName}')">清空</a> <input type="hidden" name="${idName}" value="${(idVal)!}"/> <#-- 綁定輸點擊清空時的事件--> <script> function clearDicTree(resourceName,idName) { $("input[name='"+resourceName+"']").val('');
$(
"input[name='"+idName+"']").val('');
}
</script>
</#macro>

調用macro 控件:數組

<@txtResource resourceName="parentName" idName="parentId" resourceVal="張三" idVal="1" classVal="icon2"/>

界面展現效果url

點擊「清空」按鈕,則清空文本框中的內容;點擊文本框中js也能夠寫在控件定義的 html中spa

 

3.freemark中遍歷Map:typeMap,todoMap 都是map,他們的key相同.net

     <#if typeMap?exists>
       <#list typeMap?keys as key>
         <tr>
         <td colspan="4">
         <table width="100%" border="0" cellspacing="0" cellpadding="0" class="s_todoin">
             <#assign type = typeMap[key] />
             <tr>
             <th colspan="4"><div class="s_todotit s_todotitup" name="div_${type.businessCode}" onclick="javascript:clickTodoType('${type.businessCode}');">${type.name}</div></th>
             </tr>
              <#if todoMap?exists>
              <#assign todoList =todoMap[key] />
              <#list todoList as item>
               <tr name="tr_${type.businessCode}">
                 <td width="49%" class="s_todotd"><a href="${item.refUrl!}" target="_blank" title="${item.sheetTitle!}"><#if item.sheetTitle?? && ""!=item.sheetTitle>${item.sheetTitle}<#else>未知標題</#if></a></td>
                 <td width="15%">${item.nodeName}</td>
                 <td width="12%">${item.createUserName}</td>
                 <td width="24%" >${item.createTime['time']}</td>
               </tr>
               </#list>
               </#if>
         </table>
         </td>
         </tr>
       </#list>
     </#if> code

4.freemark中遍歷多維數組;htm

    <#list oftenList as firstMenu>
   <div class="modle_usualcbw" name="often">
    <div class="modle_usualtcb" name="module">
      <input type="checkbox" value="${firstMenu.menuId}" <#if firstMenu.url?? && ""!=firstMenu.url>name="hasurl"</#if>  <#if firstMenu.userId??>checked="checked"</#if>/>${firstMenu.name}
    </div>
      <#if firstMenu.children?? && (firstMenu.children?size>0)>
                   <#assign secondMenus=firstMenu.children>
    <div class="modle_usualtcb2ws">
   
                   <#list secondMenus as secondMenu>
     <div class="modle_usualtcb2w" name="menu">
      <div class="modle_usualtcb2" name="secondMenu">
              <input type="checkbox" value="${secondMenu.menuId}" <#if secondMenu.url?? && ""!=secondMenu.url>name="hasurl"</#if> <#if secondMenu.userId??>checked="checked"</#if>/>${secondMenu.name}
       </div>
        <#if secondMenu.children?? && (secondMenu.children?size>0)>
         <#assign thirdMenus=secondMenu.children>
          <div class="modle_usualcb" name="thirdMenu">
           <ul>
           <#list thirdMenus as thirdMenu>
            <li>
              <input type="checkbox" value="${thirdMenu.menuId}" <#if thirdMenu.url?? && ""!=thirdMenu.url>name="hasurl"</#if>  <#if thirdMenu.userId??>checked="checked"</#if>/>${thirdMenu.name}
             </li>
           </#list>
           </ul>
          </div>
        </#if>
     </div>
     </#list>
    
    </div>
     </#if>
    
   </div>
 </#list>

 5.freemark中數字和字符的格式:保留小數點後2位

<input  name='currentcost' value='#{(project.progress?default(0))*(project.budgetContractA?default(0))/100;M2}' readonly='readonly'>

具體見:http://talentkep.iteye.com/blog/510756

相關文章
相關標籤/搜索