在python后端程序中植入html代码,DataTable展示数据

在python后端程序中植入html代码,DataTable展示数据

data = [list(item) for item in res]
    for item in data:
        if item[3] == 1:item[3] = '客户'
        elif item[3] == 4:item[3] = '管理员'
        html1 = "<a id='btn0' data-uid=" + str(item[0]) + " class='mr-5 btn btn-primary'>调整权限</a>";
        html1 += "<a id='btn1' data-uid=" + str(item[0]) + " class='mr-5 btn btn-danger'>删除</a>";
        item.append(html1)
    return jsonify({"data": data})
$('#userTable').on('click','#btn0',function (){
        var uid=$(this).data('uid');
        console.log(uid);
        //开始根据获得的主键userid值来修改该用户的权限
        layer.confirm('确定修改?',{
            btn:['确定','放弃']//可以无限个按钮
        },function (index,layero){
           //按钮【按钮一】的回调
            $.post(url_modify,{'userid':uid},function (res){
            console.log(res)
            if (res.flag==1){
                layer.msg("修改成功",{icon:1,time:1000})
                location.href="http://127.0.0.1:8080/admin_userinfo_access"
            }else {
                layer.msg("修改不成功",{icon:1,time:1000})
            }
        }
        },function (index){
           //按钮【按钮二】的回调
        });
    })
    $('#userTable').on('click','#btn1',function (){
        var uid=$(this).data('uid');
        console.log(uid);
        //开始根据获得的主键userid值来来删除该用户
        layer.confirm('确定删除?',{
            btn:['确定','放弃']//可以无限个按钮
        },function (index,layero){
           //按钮【按钮一】的回调
            $.post(url_del,{'userid':uid},function (res){
            console.log(res)
            if (res.flag==1){
                layer.msg("删除成功",{icon:1,time:1000})
                location.href="http://127.0.0.1:8080/admin_userinfo_access"
            }else {
                layer.msg("删除失败",{icon:1,time:1000})
            }
        })
        },function (index){
           //按钮【按钮二】的回调

        });
    })

datatable展示数据


url='http://ip:端口/路由';
$.get(url,function (res){
        console.log('----------------------------')
        $('#userTable').DataTable({
            data:res.data,
            columns:
                [
                    {title:'ID'},
                    {title:'用户名'},
                    {title:'手机号'},
                    {title:'级别'},
                    {title:'管理'}
                ]
        });
    })
上一篇:分页组件dataTable的用法


下一篇:C# List<T>/Array/ArrayList转化成DataTable