用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" >
        <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));

相关文章:

  • 2021-07-02
  • 2021-12-03
  • 2021-10-15
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
  • 2022-01-03
  • 2021-10-13
猜你喜欢
  • 2021-12-29
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
  • 2021-11-09
相关资源
相似解决方案