Using Template with Arr or Obj

by dandiebolt

HTML

<script src="https://github.com/jquery/jquery-tmpl/raw/master/jquery.tmpl.min.js"></script>
<script id="myTemplate" type="text/x-jquery-tmpl"> 
    <li>(${x} , ${y})</li>
</script>

<ol id="mylist1"></ol>
<hr/>
<ol id="mylist2"></ol>
<hr/>
<ol id="mylist3"></ol>

CSS

body {
    font-size: 12px;
}

JavaScript

var mydata1={x:1,y:2};
var mydata2=[{x:1,y:2},{x:2,y:1}]
       $("#myTemplate").tmpl(mydata1).appendTo("#mylist1");

 $("#myTemplate").tmpl(mydata2).appendTo("#mylist2");

$.each(mydata2,function(i,datum){
  $("#myTemplate").tmpl(datum).appendTo("#mylist3"); 
});