jQuery的art-template模板渲染案例

 一、需要在npm下载art-template和jquery

<script src="../node_modules/art-template/lib/template-web.js"></script>

二、ajax获取到的数据

<script>
    $(function () {
        // 获取所有的英雄
        // console.log("进入函数里面")
        $.ajax({
            type: "get",
            url: "http://127.0.0.1:5000/api/getheros",
            dataType: "json",
            success: function (result) {
                console.log(result)
               var htnlStr = template("getheros", result)
               $("tbody").html(htnlStr);
            }
        });
    });
</script>

三、模板渲染(循环方法用的是each,value是自带的,不能写成其他)

​
<script id="getheros" type="text/template">
    {{ each message }}
            <tr>
                <td>{{$value.id}}</td>
                <td>{{$value.name}}</td>
                <td>{{$value.age}}</td>
                <td>{{$value.gender}}</td>
                <td>{{$value.isdel}}</td>
                <td>{{$value.ctime}}</td>
                <td>编辑</td>
            </tr>
   {{ /each}}
</script>

​

四、需要添加到tbody里

<body>
    <div class="container">
        <table class="table table-striped">
            <thead>
                <tr>
                    <td>id</td>
                    <td>姓名</td>
                    <td>年纪</td>
                    <td>性别</td>
                    <td>软删除</td>
                    <td>创建时间</td>
                    <td>编辑</td>
                </tr>
            </thead>
            <tbody>
        
            </tbody>
        </table>
    </div>

message :为得到的数据result里面的属性

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值