Giter Club home page Giter Club logo

wu.tmpl.js's Introduction

wu.tmpl.js

极简高性能模板引擎

============

性能测试 性能测试

Usage 使用方法

模板

<!-- 注意这里的 type 不是 javascript,只是模板的容器 -->
<script id="test" type="text/html">
<ul>
  <% for(var i=0; i< list.length; i++){ %>
      <li> <%= list[i].name %> </li>
  <% } %>
</ul>
</script>

数据

<script>
var list = [
    {id: 1, name: 'name1'},
    {id: 2, name: 'name2'},
    {id: 3, name: 'name3'}
]
</script>

渲染

var tpl = document.getElementById('test').innerHTML;

var render = wu.tmpl(tpl); // 返回一个渲染函数

var result = render(); // 执行渲染得到结果

// 输出结果
document.getElementById('result').innerHTML = result;
// 上面使用的是全局变量,这样并不太好。可以把需要的参数传入
var data = {
  list: {...},
  // ... 其它变量
}

var render = wu.tmpl(tpl);
var result = render(data); // 传入参数

// ... 数据变化后,再次渲染
var result = render(data);

// 还可以这样写
var result = wu.tmpl(tpl)(data);

// 或者这样
var result = wu.tmpl(tpl, data);

结果

<div id="result">
<ul>
  
      <li> name1 </li>
  
      <li> name2 </li>
  
      <li> name3 </li>
  
</ul>
</div>

wu.tmpl.js's People

Contributors

wushufen avatar

Watchers

James Cloos avatar kevinandleekai avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.