artTempalte 渲染

编写模板(采用script标签并带有属性id和type="text/html")


<div id="slowcity-film-content-div"></div>

<script id="slowcity-film-template" type="text/html">
   {{if isAdmin}}
   
   <h1>{{author}}</h1>
   <ul>
    {{each list as value i}}
    <li>{{i+1}}:{{value}}</li>
    {{/each}}
   </ul>
   
   {{/if}}
  </script>

#渲染模板(film.js)

var data = {
    author: '宫崎骏',
    isAdmin: true,
    list: ['千与千寻', '哈尔的移动城堡', '幽灵公主', '风之谷', '龙猫']
};
var slowcity-film-html = template('slowcity-film-template', data);
document.getElementById('slowcity-film-content-div').innerHTML = slowcity-film-html;

猜你喜欢

转载自my.oschina.net/u/3698560/blog/1649712