请教各位前辈
majax请求后台json数据后,怎样才能通过级联的方式显示在页面上呢?
代码去下:这是我现在的代码,只能显示出数据,做不到级联显示。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link href="css/mui.css" rel="stylesheet" />
<script src="js/template-web.js"></script>
</head>
<body>
<ul class="mui-table-view">
<li class="mui-table-view-cell">
<a class="mui-navigate-right">
Item 1
</a>
</li>
<li class="mui-table-view-cell">
<a class="mui-navigate-right">
Item 2
</a>
</li>
<li class="mui-table-view-cell">
<a class="mui-navigate-right">
Item 3
</a>
</li>
</ul>
<button type="button" class="mui-btn mui-btn-blue mui-btn-block" id="btn1">按钮</button>
<script src="js/mui.js"></script>
<script type="text/javascript">
mui.init();
mui.plusReady(function() {
document.getElementById('btn1').addEventListener('tap', function() {
mui.ajax({
dataType:'json',
type:'GET',
url :'http://112.33.11.150:8888/listSchool',
success: succFunction,
error: function(xhr,type,errorThrown){
console.log(type);
}
});
function succFunction(data){
var str = JSON.stringify(data);
var obj = JSON.parse(str);
var ul = document.body.querySelector('.mui-table-view');
for (var i=0;i<obj.length;i++) {
var li = document.createElement('li');
li.className = 'mui-table-view-cell';
li.innerHTML = '<a class="mui-navigate-right">'+ obj[i].drivingschoolname + obj[i].drivingSchoolAddress +'</a>'
ul.appendChild(li,ul.lastChild);
}
}
});
})
</script>
</body>
</html>
2 个回复
[已删除]
你是做筛选是吗?
1***@qq.com (作者) - 90后
问题解决了,是我太弱了 当时