Getting started with the doT js template, dotjs Template
DoT. js github address:
Official website of doT. js
Instance 1: simple
<!DOCTYPE html>
Running result:
Example 2: Condition Determination
<Body> <div id = "conditionstmpl"> {{? ! It. name }}< div> you have no name </div> {{?? }}< Div> Oh, I love your name, {{= it. name }}! </Div> {{?}} </Div>
Running result:
Example 3: Cycle + condition judgment
<body><div id="evaluationtmpl"> {{ for(var prop in it) { }} {{? typeof it[prop]=='object' }} <div style="font-weight: bold;" >KEY:{{= prop }}---VALUE:</div> {{ for(var prop2 in it[prop]) { }} <div style="margin-left: 20px;" >key:{{= prop2 }}---value:{{= it[prop][prop2] }}</div> {{ } }} {{?? }} <div>KEY:{{= prop }}---VALUE:{{= it[prop] }}</div> {{?}} {{ } }}</div>
Running result:
Source code:
DoT source code and Examples
Note:
1 ,{{? Typeof it [prop] = 'object'} indicates condition judgment. The end tag is {{?}}
2 ,{{?? } Is the else for conditional judgment.
3, {and {{? Can use native js syntax, such as for, typeof, etc.
4. The template does not have to be placed in the script tag, but can also be placed in the hidden div tag.
Author:Huang Wei
Blog address:
CSDN blog homepage
ItEye blog homepage