eolinker-教你生成测试数据(三)

测试地址:

https://gitee.com/WangYC_UI/codes/vromzkdg653b4upnsefaw63

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>测试</title>
<style type="text/css">
table {
border: 1px;
font-size: 14px;
}
th,td {
padding: 10px 20px;
background: #f5f5f5;
}
</style>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
</head>
<body>
<table id="t_mock" border="0" cellspacing="0" cellpadding="0">
</table>
<script>
$.ajax({
url: "https://mockapi.eolinker.com/GtJBXkAe89306078ba5ecb1eb6e67817cd62d715ecc8261/mock/vue_minidata",
type:'post',
data: {},
success(res) {
res = JSON.parse(res)
console.log(res)
var boduTable = ''
for(var i=0;i<res.length;i++){
boduTable += "<tr><td>"+res[i].userdata.name+"</td><td>"+res[i].userdata.age+"</td><td>"+res[i].userdata.gender+"</td><td>"+res[i].userdata.hobby+"</td><td>"+res[i].school.m_school+"</td><td>"+res[i].school.h_school+"</td></tr>"
}
var headerTable = "<tr><th>姓名</th><th>年龄</th><th>性别</th><th>爱好</th><th>小学</th><th>中学</th></tr>"
// document.write(res)
$('#t_mock').html(headerTable+boduTable)
}
});
</script>
</body>
</html>