Created
January 24, 2016 17:06
-
-
Save akulubala/4d4e5868eeaef33a5c62 to your computer and use it in GitHub Desktop.
underscore template usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tpl = _.template($("#template_errors").html(),{variable: 'items'});// define variable to retrive | |
var html = tpl(response.responseJSON); //pass datas to be loop | |
$("#js-form").prepend(html); | |
// template to use | |
<script type="text/template" id="template_errors"> | |
<div class="error-list"> | |
<ul> | |
<% _.each(items,function(item,key,arr) { %> | |
<li> | |
<span><%= item %></span> | |
</li> | |
<% }); %> | |
</ul> | |
</div> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment