doT.js使用笔记

doT.js使用笔记_第1张图片
doT.js

doT.js github地址

Created in search of the fastest and concise JavaScript templating function with emphasis on performance under V8 and nodejs. It shows great performance for both nodejs and browsers.
doT.js is fast, small and has no dependencies.
  • 使用方法:

{{= }}
// for interpolation
{{ }} 
//for evaluation
{{~ }} 
//for array iteration
{{? }}
// for conditionals
{{! }}
// for interpolation with encoding
{{# }}
// for compile-time evaluation/includes and partials
{{## #}}
// for compile-time defines
  • 调用方式:

var tmpText = doT.template(模板);
tmpText(数据源);
  • 语法结构:

赋值:

//格式:
{{= }}
//示例:

for 循环结构:

//格式:
{{ for(var x in data) { }} 
    {{= key }} 
{{ } }}
//示例:

if 逻辑结构:

//格式:
{{if(conditions){ }}
{{} eles if(conditions){ }}
{{} eles{ }}
{{ }}} 
//示例:

数组:

//格式:
{{~data.array :value:index }}
//示例:

编码:

//格式:
{{!it.uri}}
//示例:

你可能感兴趣的:(doT.js使用笔记)