<!-- TODO -->
<!--使用了undersocre的each方法
第一个参数 就当前遍历的对象
第二个从那时当前遍历的索引
-->
<script type="text/template" id="template">
<div>
<%_.each(model,function(item,i){%>
<p><%-item.name%></p>
<%});%>
</div>
</script>
<script src="../lib/underscore/underscore-min.js"></script>
<script>
$(function(){
/*
* - 是直接渲染成字符
* = 直接填充在html 标签是会被渲染
* XSS攻击:跨站脚本攻击(Cross Site Scripting),
* 为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆
* 故将跨站脚本攻击缩写为XSS。
* */
/* 准备 json 数据*/
var data = [{name:'xiaoming'},{name:'xiaohong'}];
/* 参数是模板当中的字符串 使用template方法 返回一个模板对象*/
var template = _.template($('#template').html());
/*调用模板对象的时候 传入json数据 返回的就是解析过后的字符串*/
$('#box').html( template({model:data}));
});
</script>