zoukankan      html  css  js  c++  java
  • artTemplate模板自定义函数

    用artTemplate模板设置自定义函数以即自定义函数使用方法

    自定义函数

    // 百分比计算
    template.defaults.imports.percentage = function (num1, num2) {if(!num1 && !num1){
           return 0+'%';
        }else{
           return Math.round(num1 / (num1 + num2) * 100) + '%';
        }   
    }

    自定义函数使用

        <script type="text/html" id="content">
            <div class="coping-ratio-content-fl">
                <div class="coping-ratio-content-title">
                    百分比<span>{{cash,total | percentage}}</span>
                </div>
            </div>
        </script>

    数据填充

    $(".header").html(template('content',res.data));
  • 相关阅读:
    世纪末的星期
    马虎的算式
    蜜蜂飞舞
    Torry 的困惑
    级数调和
    数列
    最大最小公倍数
    蚂蚁感冒
    12.integer to Roman
    13.Roman to Integer
  • 原文地址:https://www.cnblogs.com/zimengxiyu/p/12009586.html
Copyright © 2011-2022 走看看