compile.html 547 B

123456789101112131415161718192021222324252627
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>compile-demo</title>
  6. <script src="../dist/template.js"></script>
  7. </head>
  8. <body>
  9. <h1>在javascript中存放模板</h1>
  10. <div id="content"></div>
  11. <script>
  12. var source = '<ul>'
  13. + '{{each list as value i}}'
  14. + '<li>索引 {{i + 1}} :{{value}}</li>'
  15. + '{{/each}}'
  16. + '</ul>';
  17. var render = template.compile(source);
  18. var html = render({
  19. list: ['摄影', '电影', '民谣', '旅行', '吉他']
  20. });
  21. document.getElementById('content').innerHTML = html;
  22. </script>
  23. </body>
  24. </html>