Tuesday, 15 June 2010

How can I render a template based on execution of a specific function- Javascript -



How can I render a template based on execution of a specific function- Javascript -

i have underscore template , want render specific code in template based on phone call of function. template:

<div id = "account-hover-container" style="display:none;"> <div class = "form-horizontal" id="hover-group-container"> <% _.each(obj,function(item){ %> <p class="accountname-overview"> <label for="user-create-date" class="control-label col-xs-3" id="accountname-title">name:</label> <label class="overlay-accountname"><%= item.accountname %></label> <hr id="main-overlay-hr"/> </p> <% });%> <div id="detail-container"> <div class="form-group overlay-group"> <label for="user-create-date" class="control-label col-xs-3"><%= messages.admin.account.createdaccount %></label> <label name="user-create-date" id="user-create-date" class="control-label col-xs-4"></label> </div> </div></div>

in above template want execute above each loop function(below). rest i'd render on page load.

js:

function popcheck(obj) { //obj json object having fields names , emails. //do stuff }

can phone call popcheck funtion template , display content within for-each loop function. possible?? ideas?

thanks!

you can have 2 separate template, account-hover-container-template , accountname-overview-template. can render , insert accountname-overview-template within popcheck function.

for example:

<div id = "account-hover-container" style="display:none;"> ...... <div class="accountname-overview-container"/> ...... </div> <script type="text/template" id="accountname-overview-template"> <% _.each(obj,function(item){ %> ...... <% });%> </scirpt> function popcheck(obj) { var tmpl = _.template($(#accountname-overview-template).html()); $('.accountname-overview-container').html(tmpl({obj: obj})); }

javascript templates

No comments:

Post a Comment