<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

        javascript前端模板引擎框架artTemplate使用總結(jié)-CSDN博客

        來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-27 19:33:27
        文檔

        javascript前端模板引擎框架artTemplate使用總結(jié)-CSDN博客

        javascript前端模板引擎框架artTemplate使用總結(jié)-CSDN博客:artTemplate是騰訊開源的前端模板框架,和mustache,handlerbars類似,在web項目中可以很方便的使用,上手快,如果用過mustache,那么幾乎可以快速切換到template框架上來。學(xué)習(xí)過程:1、語法介紹:數(shù)據(jù)綁定:與angularjs類似,只不過視圖與模型是單
        推薦度:
        導(dǎo)讀javascript前端模板引擎框架artTemplate使用總結(jié)-CSDN博客:artTemplate是騰訊開源的前端模板框架,和mustache,handlerbars類似,在web項目中可以很方便的使用,上手快,如果用過mustache,那么幾乎可以快速切換到template框架上來。學(xué)習(xí)過程:1、語法介紹:數(shù)據(jù)綁定:與angularjs類似,只不過視圖與模型是單
        artTemplate是騰訊開源的前端模板框架,和mustache,handlerbars類似,在web項目中可以很方便的使用,上手快,如果用過mustache,那么幾乎可以快速切換到template框架上來。

        學(xué)習(xí)過程:

        1、語法介紹:

      1. 數(shù)據(jù)綁定:與angularjs類似,只不過視圖與模型是單向的綁定,模型改變,視圖改變,反過來則不行。

      2. <script id="tpl1" type="text/template">
        	<h1>1、data mapping example</h1>
        	<h2>{{message}}</h2>
        </script>
        //js中使用模板渲染
        var data1 = {message:"hello,artTemplate is a javasript framework."};
        $("node1").innerHTML = template("tpl1",data1);
      3. 條件判斷:這里支持單一的if,也可以加入else分支,沒有else if分支。

      4. {{if isShow}}
        	<h3>(2、滿足條件展示消息:{{message}}</h3>
        {{else}}
        	<h3>(2x、條件不滿足,展示默認(rèn)消息</h3>
        {{/if}}
      5. 遍歷集合:

      6. {{each list as item index}}
        	<h3>the index of message is : {{index+1}} -> {{item}}</h3>
        {{/each}}
      7. 輔助函數(shù):可以用來將后端請求的數(shù)據(jù)進(jìn)行映射,比如1->正常,0->錯誤。在使用的時候僅需要在表達(dá)式后面通過"|func"的方式就可以,比如{{message | filterhandler}},其中filterhandler為自定義的輔助函數(shù)。

      8. 先定義一個輔助函數(shù),這里定義的是一個簡單的轉(zhuǎn)換日期格式函數(shù)。

        template.helper("date2str",function(date){
        var today = new Date(date);
        var year = today.getFullYear();
        var month = today.getMonth()+1;
        if(month<10)month = "0"+month;
        var day = today.getDate();
        if(day<10)day = "0"+day;
        return year+"-"+month+"-"+day;
         });

        使用輔助函數(shù)

        <p id="node4"></p> 
        <script id="tpl4" type="text/template">
        	<h1>4、template.helper func example</h1>
        	<h3>today is {{datenow | date2str}}</h3>
         </script>
        
        //js代碼中調(diào)用
         var data4 = {datenow:new Date()};
         $("node4").innerHTML = template("tpl4",data4);
      9. 預(yù)編譯:與使用模板不同的是,預(yù)編譯需要的是一個string類型的文檔片段,然后將數(shù)據(jù)交給預(yù)編譯后的模板進(jìn)行渲染。

      10. var tpl5 = "<h1>5、compile example</h1><h3>this is a string the type is not {{type}}</h3>";
        $("node5").innerHTML = template.compile(tpl5)({type:"text/template"});
      11. 引用子模板:

      12. <p id="node6"></p>
        <script id="tpl6" type="text/template">
        <h1>6、include child template example</h1>
        <p class="parenttemplate">
        	<h3>parent template</h3>
        	{{include 'tpl6-child'}}
        </p>
        </script>
        <script id="tpl6-child" type="text/template">
        <p class="childtemplate">
        	<h3>child template</h3>
        </p>
        </script>

        2、下載template.js庫,引入到html文件中。<script type="text/javascript" src="template.js"></script>

        3、這里給出一個綜合的例子,將前面介紹的一些語法練習(xí)一下:

        <!doctype html>
        <html>
        <head>
        <meta charset="UTF-8"/>
        <title>artTemplate example</title>
        <style type="text/css">
        *{margin:0;}
        h1,h2,h3{margin:3px;}
        h2,h3{text-indent:20px;}
        .parenttemplate{background:#ccc;width:600px;height:60px;}
        .childtemplate{background:lightblue;}
        </style>
        <script type="text/javascript" src="template.js"></script>
        <script>
         function $(id){return document.getElementById(id);}
         window.onload = function(){
         //data mapping
         var data1 = {message:"hello,artTemplate is a javasript framework."};
         $("node1").innerHTML = template("tpl1",data1);
         //if condition
         var data2 = {isShow:true,message:"hello,template"};
         $("node2").innerHTML = template("tpl2",data2);
         data2.isShow = false;
         $("node2x").innerHTML = template("tpl2",data2);
         //list foreach
         var data3 = {list:["Javascript","JQuery","artTemplate"]};
         $("node3").innerHTML = template("tpl3",data3);
         //helper function
         template.helper("date2str",function(date){
         var today = new Date(date);
         var year = today.getFullYear();
         var month = today.getMonth()+1;
         if(month<10)month = "0"+month;
         var day = today.getDate();
         if(day<10)day = "0"+day;
         return year+"-"+month+"-"+day;
         });
         var data4 = {datenow:new Date()};
         $("node4").innerHTML = template("tpl4",data4);
         //compile example
         var tpl5 = "<h1>5、compile example</h1><h3>this is a string the type is not {{type}} 
         </h3>";
         $("node5").innerHTML = template.compile(tpl5)({type:"text/template"});
         $("node6").innerHTML = template("tpl6",{});
         //escape html
         $("node7").innerHTML = template("tpl7",{message:"<span>escape html tag</span>"});
         }
        </script>
        </head>
        <body>
        	 <p id="node1"></p>
        	 <script id="tpl1" type="text/template">
        	 <h1>1、data mapping example</h1>
        	 <h2>{{message}}</h2>
        	 </script>
        	 <p id="node2"></p>
        	 <p id="node2x"></p>
        	 <script id="tpl2" type="text/template">
        	 <h1>2、if condition example</h1>
        	 {{if isShow}}
        	 <h3>(2、滿足條件展示消息:{{message}}</h3>
        	{{else}}
        	 <h3>(2x、條件不滿足,展示默認(rèn)消息</h3>
        	{{/if}}
        	 </script>
        	 <p id="node3"></p>
        	 <script id="tpl3" type="text/template">
        	 <h1>3、list example</h1>
        	 {{each list as item index}}
        	 <h3>the index of message is : {{index+1}} -> {{item}}</h3>
        	{{/each}}
        	 </script>
        	 <p id="node4"></p>
        	 <script id="tpl4" type="text/template">
        	 <h1>4、template.helper func example</h1>
        	<h3>today is {{datenow | date2str}}</h3>
        	 </script>
        	 <p id="node5"></p>
        	 <p id="node6"></p>
        	 <script id="tpl6" type="text/template">
        	 <h1>6、include child template example</h1>
        	 <p class="parenttemplate">
        	 <h3>parent template</h3>
        	{{include 'tpl6-child'}}
        	 </p>
        	 </script>
        	 <script id="tpl6-child" type="text/template">
        	 <p class="childtemplate">
        	 <h3>child template</h3>
        	 </p>
        	 </script>
        	 <p id="node7"></p>
        	 <script id="tpl7" type="text/template">
        	 <h1>7、escape html tag example</h1>
        	 <h3>origin expression : {{#message}}</h3>
        	 <h3>after escape ==> : {{message}}</h3>
        	 </script>
        	</body>
        </html>

        運行這個示例,可以得到如下的效果:

        2.png

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        javascript前端模板引擎框架artTemplate使用總結(jié)-CSDN博客

        javascript前端模板引擎框架artTemplate使用總結(jié)-CSDN博客:artTemplate是騰訊開源的前端模板框架,和mustache,handlerbars類似,在web項目中可以很方便的使用,上手快,如果用過mustache,那么幾乎可以快速切換到template框架上來。學(xué)習(xí)過程:1、語法介紹:數(shù)據(jù)綁定:與angularjs類似,只不過視圖與模型是單
        推薦度:
        標(biāo)簽: js 模板 art
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 一本色道久久88亚洲综合| 免费看片免费播放| 国产av无码专区亚洲av果冻传媒| 亚洲视频在线观看免费视频| 亚洲一区二区三区AV无码| 一个人看的www免费高清| 亚洲精品成人区在线观看| fc2免费人成在线视频| 国产亚洲美女精品久久久| 韩国免费A级毛片久久| 久久久久久久尹人综合网亚洲| a级成人免费毛片完整版| 久久亚洲国产视频| 最好看最新的中文字幕免费| 99ri精品国产亚洲| 久久久久久99av无码免费网站| 亚洲熟妇无码一区二区三区| 日韩中文字幕免费| EEUSS影院WWW在线观看免费 | 韩国二级毛片免费播放| 亚洲AV无码一区二区三区网址| 免费一级肉体全黄毛片| 波霸在线精品视频免费观看| 亚洲高清中文字幕| 成人一a毛片免费视频| 午夜成人无码福利免费视频| 无码国产精品一区二区免费I6| 亚洲成AV人片高潮喷水| 国产亚洲精品精品国产亚洲综合| 久久久精品免费视频| 中中文字幕亚洲无线码| 亚洲精品99久久久久中文字幕| 国内精品免费视频精选在线观看| 亚洲avav天堂av在线网爱情| 免费一看一级毛片| 午夜精品免费在线观看| 亚洲精品无码久久久久YW| 精品亚洲一区二区| 日韩免费一区二区三区| 污污网站18禁在线永久免费观看| 亚洲妇女无套内射精|