doT.js调用接口数据

上代码

代码demo   http://www.cnblogs.com/kuikui/p/3505768.html


<div id="evaluation"></div>



<script type="template" id="dotTmpl">
    <table class="am-table am-table-bordered am-table-striped am-text-nowrap">
        <thead>
        <tr>
            <th class="table-check">序号</th>
            <th class="table-type">用户账号</th>
            <th class="table-author am-hide-sm-only">姓名</th>
            <th class="table-date am-hide-sm-only">角色</th>
            <th class="table-date am-hide-sm-only">手机号</th>
            <th class="table-set">当前状态</th>
            <th class="table-set">操作</th>
        </tr>
        </thead>
        <tbody>
        <thead class="admin_back_th">

        </thead>
        {{ for(var i=0;i<it.length;i++){ }}

            <tbody id="">
                <tr>
                    <td>{{=i}}</td>
                    <td οnclick="demo1('{{=it[i].manageid}}')">{{=it[i].loginAcct}}</td>//添加事件
                    <td>{{=it[i].roleName}}</td>
                    <td>{{=it[i].roleName}}</td>
                    <td>{{=it[i].loginAcct}}</td>
                    <td>{{=it[i].roleName}}</td>
                    <td>{{=it[i].roleName}}</td>
                </tr>
            </tbody>
        {{ }    }}
        </tbody>
    </table>
    <div id="page112"></div>
</script>
<script>
    function demo1(id) {
        alert(id);
    }
    function demo(curr) {
        var nicName=$("#search").val();//用户姓名

        $.ajax({
            type:"GET",
            url:"/mgr/api/v1/manage/user/sysUserList",
            //url:'assets/json/tsconfig.json',
            dataType:"json",
            contentType:"application/json",
            data:{
                "page":'usersSystem',
                "nicName":nicName,
                "pageCount":curr || 1,
                "pageSize":'3'
            },
            success:function (data) {
                $("#main").empty();
                if(data.code=="OK"){
                    console.log(data.body.totalSum);
                    var i=0;
                    var pathml="";
                    if(data.body.results.length<1){
                        $(".nohave").show();
                    }else {
                        $(".nohave").hide();
                        var data1=data.body.results;
                        // 通过dot.template调用你所写的dot.JS。
                        var tmpl = doT.template($("#dotTmpl")[0].text);
                        // 将数据扔进templ中。并在DIV中显示出来
                        $("#evaluation").html(tmpl(data1));

                        //显示分页
                        laypage({
                            cont : 'page112', //容器。值支持id名、原生dom对象,jquery对象。【如该容器为】:<div id="page1"></div>
                            pages : data.body.totalSum, //通过后台拿到的总页数
                            curr : curr || 1, //当前页
                            skip: true,
                            first:false,
                            last:false,
                            jump : function(obj, first) { //触发分页后的回调
                                if (!first) { //点击跳页触发函数自身,并传递当前页:obj.curr
                                    demo(obj.curr);
                                }
                                $("#page112").append("<div class='page'>共:"+ data.body.totalSum +"页</div>");
                            }
                        });
                    }
                }else if(data.message=="relogin"){
                    login();
                    setTimeout(function () {
                        window.location.href="login.html";
                    },100);
                }else{
                    var txt=data.message;
                    window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.info);
                    return false;
                }


            },
            error:function (error) {
                var txt="获取数据失败请稍后再试!";
                window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.info);
                return false;
            }
        })
    };
    //运行
    demo();
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值