zoukankan      html  css  js  c++  java
  • template.js 模版内调用外部JS方法

    template.js 一款 JavaScript 模板引擎,简单,好用。提供一套模板语法,用户可以写一个模板区块,每次根据传入的数据,生成对应数据产生的HTML片段,渲染不同的效果。
    模版定义如下:

    <script type="text/html" id="list">
    	<p>
    		<span>{{price}}</span>
    		<span style="float:right">{{costTypeName}}</span>
    	</p>
    </script>
    

     {{}}里面的属性代表将被替换的数据,使用方法如下:

    html = template("list", {price:200,costTypeName:"测试"});
    选然后的html为:
    <p>
    <span>200</span>
    <span style="float:right">测试</span>
    </p>

    可是如果我们想要让price的200变为¥200.00怎么办呢?只需如下几步即可
    1.创建全局帮助函数

    template.helper("fromatMoney", function (x) {
    	return "¥" + Duanjt.Float.ToFloat(x, 2);
    });
    

    2.修改模版

    <script type="text/html" id="list">
    	<p>
    		<span>{{fromatMoney price}}</span>
    		<span style="float:right">{{costTypeName}}</span>
    	</p>
    </script>
    

    注意:需要引入template.js文件 开源地址: https://github.com/aui/artTemplate

  • 相关阅读:
    数据结构实现(四)二叉查找树java实现
    数据结构实现(三)二叉树
    git
    抓包原理
    数据结构实现(二)队列
    86. Partition List
    82. Remove Duplicates from Sorted List II
    83. Remove Duplicates from Sorted List
    排序算法总结
    上下文切换详解
  • 原文地址:https://www.cnblogs.com/duanjt/p/6382278.html
Copyright © 2011-2022 走看看