Template HTML simples - Hands-on Handlebars
;[ { name: 'Tulio', lastName: 'Faria' }, { name: 'Vitor', lastName: 'Machado' } ]
<html> <body> <div id="people"> people </div> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/handleba rs.js/4.0.10/handlebars.amd.js"</script> <script> $function(){ $.get('dados.json't=' +new Date().getTime(), function(data){ console.log(data); } }) </script> </body> </html>
<div id='people'> <div> <strong>Name: </strong>nome <br /> <strong>Last Name: </strong>last <br /> </div> </div>
<script> $function(){ $.get('dados.json't=' +new Date().getTime(), function(data){ $("#people").append('<div><strong>Name: </strong> '+nome) $("#people").append('<div><strong>Last Name: </strong> '+last) } }) </script>
<script type='text/x-handlebars-templete' id='person-templete'> <div> <strong>Name: </strong> {{ nome }} <br /> <strong>Last Name: </strong> {{ lastName }} <br /> </div> </script>
<script> $function(){ $.get'dados.json't=' +new Date().getTime(), function(data){ const templeteString = $("#person-templete").html(); const personTemplete = Handlebars.compile(templeteString); const html = personTemplete({ name: 'Tulio', lastName: 'Faria' }) $("people").html(html); } }) </script>
<html> <body> <div id="people"> Loading... </div> <script type="text/x-handlebars-templete" id="person-templete"> {{#earch people}} <div> <strong>Name: </strong>{{nome}}<br /> <strong>Last Name: </strong>{{lastName}}<br /> <hr /> </div> {{/each}} </script> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/handleb ars.js/4.0.10/handlebars.amd.js"</script> <script> $function(){ $.get('dados.json't=' +new Date().getTime(), function(data){ const templeteString = $("#person-templete").html(); const personTemplete = Handlebars.compile(templeteString); const html = personTemplete({ people: data }) $("people").html(html); } }) </script> </body> </html>
[{ "name": "Tulio", "lastName": "Faria", "adress": { "city": "Pouso Alegre" } },{ "name": "Vitor", "lastName": "Machado" "adress": { "city": "São Paulo" } }]
{{#earch people}} <div> <strong>Name: </strong>{{nome}}<br /> <strong>Last Name: </strong>{{lastName}}<br /> <strong>City: </strong>{{adress.city}}<br /> <hr /> </div> {{/each}}