template-web.js 引用變量、函數(過濾器)、過濾器傳參、輸出html 模板


1.關鍵字   $imports.+變量/函數

{{if $imports.myParseInt(b.health_money)}}
       <span class="num">+{{b.health_money}}積分</span>
{{else}}
       <span class="num org">{{b.health_money}}積分</span>
 {{/if}}

 

<img src="{{$imports.url+ data.img}}" alt="">

 

2.拓展方法(過濾器)

template.defaults.imports.+方法名 = function ( 參數 ) {

}

template.defaults.imports.myParseInt = function (str) {
        if ( parseInt(str) > 0 ) {
            return 1;
        } else {
            return 0;
        }
};

使用

<span class="num org">{{b.health_money | myParseInt}}</span>

2.拓展方法(過濾器),產多個參數

template.defaults.imports.tailFour = function (a,b,c) {
       ...
};

使用 (多個參數以逗號隔開)

<div>{{ a|tailFour:b,c }}</div>

 

4.輸出html 模板

第一種方法: 將{{content}}寫成 {{#content}}

第二種方法:template.config("escape", false);

<div class="content">
                {{#content}}
            </div>

 

更多詳情請參考:  https://www.jianshu.com/p/d8d8e19157e0


免責聲明!

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



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