1. 程式人生 > >json資料與html模版的轉換

json資料與html模版的轉換

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<script src="http://code.jquery.com/jquery.js" type="text/javascript"></script>
<script src="../../jquery.tmpl.js" type="text/javascript" ></script>
<script src="../../jquery.tmplPlus.js" type="text/javascript"></script>
<ul id="movieList"></ul> 
 
<script id="movieTemplate" type="text/x-jquery-tmpl"> 
<li><a href="${strurl}">${Name}</a> -----(${ReleaseYear})</li> 
</script> 
 
<script type="text/javascript"> 
var movies = [ 
{ Name: "The Red Violin", ReleaseYear: "1998" ,strurl:"2015"}, 
{ Name: "Eyes Wide Shut", ReleaseYear: "1999",strurl:"2016" }, 
{ Name: "The Inheritance", ReleaseYear: "1976",strurl:"2017" } 
]; 
$( "#movieTemplate" ).tmpl( movies ) 
.appendTo( "#movieList" ); 

 </script>   
</body>
</html>