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>
  • 相关阅读:
    linux环境变量
    linux命令系列 ls
    为什么寄存器比内存快?
    Python RE
    Python List Comprehension
    转:C++ 关键字 inline详细介绍
    转:c++里关于cerr,clog,cout三者的区别
    CS项目总结
    selenium 添加动态隧道代理
    python 进程/线程/协程 测试
  • 原文地址:https://www.cnblogs.com/mmit/p/12624530.html
Copyright © 2011-2022 走看看