html部分:
<ul id="medicine_type_template">
<textarea class="hide" id="addressTemp">
<!-- for: ${data} as ${pro} -->
<li class="address_cont" id="address_cont">
${pro.name}
</li>
<!--/for -->
</textarea>
</ul>
josn部分
{
"status": "Y",
"data": [{
"id": "0001",
"name": "张三",
"province": "山东",
"city":"烟台",
"area":"芝罘区",
"address": "新城街道",
"mobile":"18660051713",
"telphone": "",
"zip": "000000",
"default": true
}]
}
js部分
var etpl=require('etpl'); //导入插件
var liTemplate=$('#addressTemp').val(); //找存放的元素
var renderData = function(data) {
var render = etpl.compile(liTemplate); // 模板编译
var _list = render(data)
$('#medicine_type_template').html(_list); // 获取到的数据存入模板
};
var getData = function() {
$.ajax({
url: seajs.api.address,
type: 'GET',
dataType: 'json',
success: function(res) {
if(res.status==="Y"){
renderData(res) //取数据
}else{
console.log('失败');
}
}
});
}
getData();