您当前的位置: 首页 >  Java

彭世瑜

暂无认证

  • 1浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

doT.js:一个Node.js和浏览器环境下快速简洁的javascript模板引擎

彭世瑜 发布时间:2020-07-19 23:29:48 ,浏览量:1

简介: The fastest + concise javascript template engine for Node.js and browsers.

译文: Node.js和浏览器环境下最快+简洁的javascript模板引擎

文档:http://olado.github.io/doT/index.html

下载

# 开发版 5.1K
wget https://raw.githubusercontent.com/olado/doT/master/doT.js

# 压缩版 3.3K
wget https://raw.githubusercontent.com/olado/doT/master/doT.min.js

Node.js环境使用

npm install dot

浏览器使用


基本模板语法

{{ }}   for evaluation
{{= }}  for interpolation
{{! }}  for interpolation with encoding
{{# }}  for compile-time evaluation/includes and partials
{{## #}}    for compile-time defines
{{? }}  for conditionals
{{~ }}  for array iteration

基本使用






  {{=it.name}}







  var data = {
    name: "Tom",
  };

  var template = doT.template(document.getElementById("content-tmpl").text);
  // 显示渲染结果
  document.getElementById("content").innerHTML = template(data);

更多使用示例


  
    
    
    Document

    
      赋值
      {{=it.name}}

      循环map
      {{for(var key in it.attrs) { }}
        {{=key}}: {{=it.attrs[key]}}
      {{ } }}

      数组
      {{~it.pets:value:index}}
        {{=index}}: {{=value}}
      {{~}}

      条件
      {{? it.sex == 0}}
      女
      {{??}}
      男
      {{?}}
    

    
  

  
    
  

  
    var data = {
      name: "Tom",
      sex: 0,
      pets: ["dog", "cat", "pig"],
      attrs: {
        age: 23,
        phone: 123456,
      },
    };

    var template = doT.template(document.getElementById("content-tmpl").text);
    document.getElementById("content").innerHTML = template(data);
  


参考资料 http://www.jq22.com/jquery-info8648

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.1130s