artTemplate的函数使用

<script id="main_panel_big_sale_template" type="text/html">
           {{each products as product i}}
       {{if i < 3}}
       <li>
       <img src="{{product.pictographicIconList[0].image.url | getImageUrl}}" data-imgname="{{product.pictographicIconList[0].image.url}}">
           <div class="flash-time-box">
           <span>2015-02-09</span>
           </div>
           <strong class="marque">{{product.name}}</strong>
       <strong class="libelle">{{product.description}}</strong>
       <div class="no-picto">
           <span class="prod-tip">
           <img src="img/grey.png" data-original="img/icon.png">
           </span>
           <span class="italic black">
           <span class="cny-curr">¥&nbsp;{{product.price.value | formatPrice: 'integer'}}</span><span class="decimal">{{product.price.value | formatPrice: 'decimal'}}</span>
       </span>
       </div>
       </li>
       {{/if}}
       {{/each}}
</script>

JS:

template.helper('formatPrice', function(price, type) {
    if(price){
        var arrayPrice = price.toString().split(".");
        if(type == 'integer') {
            return arrayPrice[0]?arrayPrice[0]:"0";
        }else if (type =='decimal') {
            return arrayPrice[1]?arrayPrice[1].length == 1?"."+arrayPrice[1]+"0":"."+arrayPrice[1]:".00";
        }
    }else{
        if(type == 'integer') {
            return "0";
        }else if (type =='decimal') {
            return ".00";
        }
    }
});

猜你喜欢

转载自blog.csdn.net/dududu01/article/details/78527570