• Jade之Interpolation


    Interpolation

    jade为不同的需求提供了一些特殊的操作符。详见Github

    = 将右边的值赋予左边,或者替换为右边变量的值。

    //- 赋值,js格式即可。
    - var title = "On Dogs: Man's Best Friend";
    
    //- 替换,注意左边无空格右边需有空格。
    h= title
    

    #{val}将引用处替换为val变量的值。

    - var author = "Tom";
    
    //- 编译生成的html中为Tom,而不是#{author}
    p Written with love by #{author}
    

    在属性那一章的特殊属性中曾提到,类似<这样的特殊符号编译后将为&lt。同样在使用#{val}的时候,若val变量的值含有这些特殊符号的时候,编译也会变成&lt这样的形式。
    为了避免出现如上形式,可以采用!{val}

    jade:

    - var riskyBusiness = "<em>Some of the girls are wearing my mother's clothing.</em>";
    
    .quote
      p Joel: !{riskyBusiness}
    

    html:

    <div class="quote">
      <p>Joel: <em>Some of the girls are wearing my mother's clothing.</em></p>
    </div>
    

    如果需要在文本内容中插入标签的话,可以使用#[...]

    jade:

    p.
      If you take a look at this page's source #[a(target="_blank", href="https://github.com/jadejs/jade/blob/master/docs/views/reference/interpolation.jade") on GitHub],
      you'll see several places where the tag interpolation operator is
      used, like so.
    

    html:

    <p>If you take a look at this page's source <a target="_blank" href="https://github.com/jadejs/jade/blob/master/docs/views/reference/interpolation.jade">on GitHub</a>,
      you'll see several places where the tag interpolation operator is
      used, like so.
    </p>
    

    循环

    jade支持for / while / each三种循环方式,其中for / while均与常见的循环一样。

    each循环可以用来遍历整个数组。

    jade:

    - var name = ['Tom', 'Jim', 'Alex', 'Jack'];
    each i in name
      p= i
    

    html:

    <p>Tom</p>
    <p>Jim</p>
    <p>Alex</p>
    <p>Jack</p>
    
  • 相关阅读:
    身份证验证(c#和js)
    获取焦点问题
    关于加载设计器遇到一个或多个错误问题的解决方案
    关于如何使用自定义的结束消息循环的方式 (转载)
    多种重要源码下载
    关于线程同步(转载)
    ArrayList的使用技巧
    一些所谓有利于家庭生活的优点
    080801 30℃
    080731 31℃
  • 原文地址:https://www.cnblogs.com/wsy06/p/4986213.html
Copyright © 2020-2023  润新知