zoukankan      html  css  js  c++  java
  • 模板字符串应用

    art-template:解决拼接字符串更加方便

    【1】简单字符串应用

    str = `

            <ul>

                <li>${student[index].name}</li>

                <li>${student[index].sex}</li>

            </ul>

        `;

    【2】与文件内容关联

    const template = require('art-template');

    const path = require('path');

    const views = path.join(__dirname, 'views', '2');

    const htmlStr = template(views, {

    sname: 'macro',

    content: '<span>243</span>'

    });

    console.log(htmlStr);


    //与.art文件关联

    <div>

            <%=sname%>

    </div>

    <div>{{sname}}</div>

    <p>{{2+4}}</p>

    <p>{{10>3?4:5}}</p>

    <p>{{content}}</p>

    <p>{{@ content}}</p>  // 解析<spans></span>

    [3]逻辑判断条件

    const htmlStr = template(views, {

    age: 23,

    students: [{

    name: 'macr0',

    age: 4,

    sex: 'male'

        }, {

    name: 'macr0',

    age: 24,

    sex: 'male'

        }, {

    name: 'macr0',

    age: 14,

    sex: 'male'

        }]

    });

    //

    {{if age >= 16}}

        可以考取大学

    {{else}}

        回高中读书

    {{/if}}

    <ul>

    {{each students}}

    <li>

    {{$value.name}}

    {{$value.age}}

    {{$value.sex}}

    </li>

    {{/each}}

    </ul>

  • 相关阅读:
    集合的整体
    StringBuffer类中的东西
    ChickHouse安装介绍
    Flink集群搭建
    hadoop-MapReduce总结
    hadoop-hdfs
    linux命令总结
    linux
    shall 2-13
    String 类的其他功能
  • 原文地址:https://www.cnblogs.com/macro-renzhansheng/p/13054717.html
Copyright © 2011-2022 走看看