zoukankan      html  css  js  c++  java
  • art-template渲染真实数据--后台接口(难度:3颗星)

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <script src="./lib/js/jquery.min.js"></script>
        <script src="./lib/js/art-template.js"></script>
        <title>Document</title>
    </head>
    <body>
        <div id="middle">
            <!-- 在里面渲染真实数据 -->
        </div>
        <script type="text/html" id="article-detail">
            {{each articles value index}}
            <h3 class="title">{{value.title}}</h3>
            <p class="content">{{#value.content}}</p>
            {{/each}}
        </script>
        <script>
            $.ajax({
                type:'get',
                url:'https://wwwxxxxxxxxxxxx',
                data:{
                        xxxxxxxxxxxx
                },
                dataType:'JSON',
                success:res => {
                    console.log(res);
                    const articles=res.Data[0];
                    console.log(articles);
                    const htmlStr=template('article-detail',articles);
                    $('#middle').html(htmlStr);
                },
                error:msg=>{
                    console.log(msg);
                }
            });
        </script>
    </body>
    </html>
     
     
    与下面实现功能一样
     
     
    <!DOCTYPE html>
    <html lang="zh-cn">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="./lib/css/bootstrap-main.css">
        <script src="./lib/js/jquery.min.js"></script>
        <script src="./lib/js/art-template.js"></script>
        <title>art-template渲染</title>
    </head>

    <body>
        <div class="col-sm-11" id="middle">
        </div>
        <script type="text/html" id="article-detail">
            <h3 class="title">{{title}}</h3>
            <h5 class="editor">作者:{{nickName}} &nbsp;发布于:<span class="time">{{time.substring(0,10)}}</span> &nbsp;阅读数:<span
                    class="read-number">{{viewCount}}</span></h5>
            <div class="detail">
                <p>{{#content}}</p>
            </div>
            <span>喜欢:{{likeCount}}</span>
        </script>

        <script>
            $.ajax({
                type: 'get',
                url: "https://www.xxxxxxxapi/article?articleId=1",
                dataType: 'JSON',
                success: res => {
                    // console.log(res);
                    var article = res.Data[0].article;
                    console.log(article);
                    const htmlStr = template('article-detail', {
                        title: article.title,
                        nickName: article.nickName,
                        viewCount: article.viewCount,
                        content: article.content,
                        time: article.publishTime,
                        likeCount: article.likeCount
                    });
                    $('#middle').html(htmlStr);
                },
                error: msg => {
                    console.log(msg);
                }
            })
        </script>
    </body>

    </html>
  • 相关阅读:
    6.简易计算器
    5.用户密码管理
    4.方法重载
    3.对象数组做参数
    2.迷你DVD管理系统
    1.二维数组计算班级成绩
    31.向数组中插入一个元素
    30.使用Arrays类的各种方法
    Java开发中的23种设计模式详解(转)
    个人代码归档
  • 原文地址:https://www.cnblogs.com/mmit/p/12624530.html
Copyright © 2011-2022 走看看