GithubHelp home page GithubHelp logo

handlebarsjs's Introduction

handlebarsjs

1.前后端分离原理图

2.字符串拼接

`

` `<script> //数据 var data={ name:'小林', birth:'1991.02.07', home:'**', job:'前端' }; var str = ""; str += "
姓名:"+data.name+"
"; str += "
出生日期:"+data.birth+"
"; str += "
出生地:"+data.home+"
"; str += "
职业:"+data.job+"
"; $(".card").html(str); </script>` ## 3. handlebarsjs ## 1.一条渲染 <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/2.0.0/handlebars.js"></script> <script id="card-template" type="text/x-handlebars-template">
姓名:{{name}}
出生日期:{{birth}}
出生地:{{home}}
职业:{{job}}
</script>
<script> //数据 var data={ name:'小林', birth:'1991.02.07', home:'**', job:'前端' }; var t = $("#card-template").html(); // console.log(t); var f = Handlebars.compile(t); // console.log(f);s var h = f(data); $(".card").html(h); </script> 2.二条渲染 <script id="card-template" type="text/x-handlebars-template"> {{#each this}}
姓名:{{name}}
出生日期:{{birth}}
出生地:{{home}}
职业:{{job}}
{{/each}} </script>
<script> //数据 var data=[ { name:'小林', birth:'1991.02.07', home:'**', job:'前端' }, { name:'小飞', birth:'1992.02.07', home:'**', job:'前端' } ] var t = $("#card-template").html(); // console.log(t); var f = Handlebars.compile(t); // console.log(f);s var h = f(data); $(".card").html(h); </script> ## 4. handlebarsjs特点 ## 1.避免在js中写"html代码" 2.可读性好 3.易维护 ## 5. handlebarsjs特点 ##

handlebarsjs's People

Contributors

chenlin1 avatar

Watchers

 avatar  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.