Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
html has one characteristic: some will become infinite decimals decimals.
For example 1.05, it may appear as 1.049999999999 ......
May be used in javascript .toFixed (value); or the like, rounded off, to retain fixed decimal places.
However, art-template template rendering does not support the use of the direct method in the template.
Then you need to use the filter art-template templates.
grammar:
<!--HTML-->
<script type="text/html" id="template">
{{date|过滤器名称}}
</script>
template.defaults.imports.过滤器名称 = function(date){
处理内容
return 处理结果
};
For chestnut:
<div class="box"></div>
<script type="text/html" id="template">
<div class="total-price">
{{list.unit-price*list.num|format}} 元
</div>
</script>
render(data){
// art-template过滤器
template.defaults.imports.format = function(n){
return n.toFixed(2);
};
// art-template模板渲染
$(".box").html(template('template',{list:data}));
}
FIG Effect:
original:
using a filter:
Note that the filter must have a return value.
And filters as well as other formulations.