HTML
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>homework</title>
<link rel="stylesheet" href="css/core.min.css">
<link rel="stylesheet" href="js/swiper/swiper.min.css">
<link rel="stylesheet" href="css/demo1.css">
<script src="js/jquery-1.12.4.min.js"></script>
</head>
<body>
<div class="list-content">
<table class="list-std">
<thead>
<tr>
<th width="50">序</th>
<th width="370">资源名称</th>
<th width="160">提供机构</th>
<th width="110">浏览次数</th>
<th width="120">更新时间</th>
<th>评分</th>
</tr>
</thead>
<tbody id="resource-list">
</tbody>
</table>
</div>
<script type="text/x-template" id="list-tmpl">
{{#list}}
<tr {{#dis}}class="disable" {{/dis}}>
<td>{{index}}</td>
<td><span class="resource-title"><a
href="{{href}}">{{source}}</a></span></td>
<td>{{city}}</td>
<td>{{seenum}}</td>
<td>{{date1}}</td>
<td>
<div class="{{star}}"></div>
</td>
</tr>
{{/list}}
</script>
<script src="js/mustache.min.js"></script>
<script src="mock/mock-min.js" ></script>
<script src="js/test_demo04.js"></script>
<script src="js/index.js"></script>
</body>
</html>
JS
1.Index.js
(function(win, $) {
var templ = $('#list-tmpl').html();
var $resourceList = $('#resource-list');
var rederData = function(data) {
$resourceList.append(Mustache.render(templ, data));
}
$.ajax({
url: 'getData',
type: 'get',
dataType: 'json',
success: function(data) {
rederData(data);
}
})
})(this, jQuery);
2.test_demo04.js
Mock.mock("getData", function(option) {
return Mock.mock({
"list|9-20": [{
'index|+1': 1,
href: 'detail.html?rowguid=@guid',
source:'@cword(1,10)',
city: '@city',
seenum: "@integer(555,5555)",
date1: "@date(yyyy年MM月dd日)",
star: 'score score-@integer(1,5)'
}]
});
});