Sample code snnipet

var products = [
{id:1,price:34},
{id:2,price:44},
{id:3,price:54}
];
var sum = 0;
for(i=0;i”);
h1.html(products[i].price);
$(“#result”).append(h1);
}
});


=

http://js/lodash.min.js
http://js/handlebars.min.js
http://js/jquery.min.js
http://js/backbone-min.js

var products = [
{id:1,price:34, tags:[“a”,”b”]},
{id:2,price:44, tags:[“a”,”c”]},
{id:3,price:54, tags:[“c”,”d”]}
];

$(document).ready(function(){
var template_src = $(“#t3”).text();
var template = _.template(template_src);

for(i=0;i


div id=”result”></div>

{{ price }}

      {{#each tags}}

    • {{ this }}

{{/each}}

Categories

      {{#each cat}}

    • {{ type }}

{{/each}}

http://js/lodash.min.js
http://js/handlebars.min.js
http://js/jquery.min.js
http://js/backbone-min.js

var products = [
{id:1,price:34, tags:[“a”,”b”],cat:[{type:”cat1″},{type:”cat2″}]},
{id:2,price:44, tags:[“a”,”c”],cat:[{type:”cat1″},{type:”cat2″}]},
{id:3,price:54, tags:[“c”,”d”],cat:[{type:”cat1″},{type:”cat2″}]}
];

$(document).ready(function(){
var template_src = $(“#t4”).html();
var template = Handlebars.compile(template_src);

for(i=0;i


{{ price }}

      {{#each tags}}

    • {{ this }}

{{/each}}

Categories

      {{#each cat}}

    • {{ type }}

{{/each}}

http://js/lodash.min.js
http://js/handlebars.runtime.js
http://js/templates.js
http://js/jquery.min.js
http://js/backbone-min.js

var products = [
{id:1,price:34, tags:[“a”,”b”],cat:[{type:”cat1″},{type:”cat2″}]},
{id:2,price:44, tags:[“a”,”c”],cat:[{type:”cat1″},{type:”cat2″}]},
{id:3,price:54, tags:[“c”,”d”],cat:[{type:”cat1″},{type:”cat2″}]}
];

$(document).ready(function(){
// var template_src = $(“#t4”).html();
// var template = Handlebars.compile(template_src);
var template = Handlebars.templates[‘t4’]
;
for(i=0;i


Hello

{{#if male}}
Mr.
{{/if}}

{{#if female}}
Ms.
{{/if}}

{{firstName}} {{lastName}}

http://js/lodash.min.js
http://js/handlebars.min.js
http://js/jquery.min.js
http://js/backbone-min.js

var institute = {‘firstName’:”Tech”,’lastName’:”Masters”}
var person1 = {‘firstName’:”Neil”,’lastName’:”Armstrong”, male:true}
var person2 = {‘firstName’:”Drew”,’lastName’:”Barrymore”, female:true}

$(document).ready(function(){
var template_src = $(“#t6”).html();
var template = Handlebars.compile(template_src);

$(“#result”).append( template(institute));
})


Name: {{ name }}

Price: {{ price }}

Quantity: {{ quantity }}

Total Price: {{ total sign=’$’}}

http://js/lodash.min.js
http://js/handlebars.min.js
http://js/jquery.min.js
http://js/backbone-min.js

var product = {id:1,name:”Macbook Pro”,price:1799,quantity:5};

// product.total = product.quantity*product.price;

Handlebars.registerHelper(“total”,function(item){
return item.hash.sign + ” ” + (this.quantity * this.price);
})

$(document).ready(function(){
var template_src = $(“#t7”).html();
var template = Handlebars.compile(template_src);

$(“#result”).append( template(product));
})


IdNameRoll{{#each students}}{{/each}}

{{id}} {{name}} {{roll}}

http://js/lodash.min.js
http://js/handlebars.min.js
http://js/jquery.min.js
http://js/backbone-min.js

var data = [
{name:”A”,id:1,roll:12345},
{name:”A”,id:1,roll:12345},
{name:”A”,id:1,roll:12345},
{name:”A”,id:1,roll:12345},
{name:”A”,id:1,roll:12345},
];

$(document).ready(function(){
var template_src = $(“#t7”).html();
var template = Handlebars.compile(template_src);
$(“#result”).append( template({students:data}));
});

——

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s