ajax对list中的list进行循环

后台返回的数据结构:
---------------------

ajax解释方法:
------------------------
$(function () {
$('#check').click(function () {
$.ajax({
url:"/sc/find",
type:"post",
data:{},
success:function (data) {
//循环list中的list
var Temp = ''//先定义一个变量为空
$.each(data, function (i, item) {//对第一层list进行循环
Temp += "<h4> " + item.scClass + " " + item.scBzr + "</h4>\n" +//拿到第一层循环的对象值,循环放入Temp变量中,下面直到循环结束前都是固定内容
" <ol>\n" +
" <table class=\"table table-bordered\">\n" +
" <thead>\n" +
" <tr>\n" +
" <th>姓名</th>\n" +
" <th>学号</th>\n" +
" <th>性别</th>\n" +
" <th>年龄</th>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody>\n"

$.each(item.userList, function (i, item) {//进行list中包含的list循环

Temp += " <tr>\n" +//拿到第二层循环对象的值以及固定html代码循环放入Temp变量中
" <td>" + item.stuName + "</td>\n" +//拿到list中的list的对象值,进行赋值
" <td>\" + item.num + \"</td>\n" +
" <td>\" + item.sex + \"</td>\n" +
" <td>\" + item.age + \"</td>\n" +
" </tr>\n"
})

Temp += " </tbody>\n" +
" </table>\n" +
" </ol>"
});

$("#search").append(Temp)//在id为search的后面加入上面设置好的代码

console.log(data);
},
error:function (e) {
alert("错误!!");
}
});

转载于:https://www.cnblogs.com/aqihao/p/9561030.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值