【问题标题】:What does != do in jade/pug?!= 在玉/哈巴狗中做什么?
【发布时间】:2016-06-18 04:31:51
【问题描述】:

!= 在下面的玉代码中如何工作.. != messages()

extends layout

block content
 .spacer
 .container
  .row
   .col-lg-8.col-lg-offset-2.col-md-10.col-md-offset-1
    a(class='btn btn-tiny btn-primary' href='/manage/categories/add') Create Category
    h1= title
     small
      a(href='/manage/articles')  Manage Articles
    != messages()
    table(class='table table-striped')
     tr
      th Category Title
      th
     each category, i in categories
      tr
       td #{category.title}
       td 
        a(class="btn btn-tiny btn-default" href="/manage/categories/edit/#{category._id}") Edit

app.js

app.use(require('connect-flash')());
app.use(function (req, res, next) {
  res.locals.messages = require('express-messages')(req, res);
  next();
});

【问题讨论】:

  • 这似乎是一种无需父标签即可输出内容的方式。
  • 部分记录了here“未转义的缓冲代码”)。

标签: javascript node.js pug


【解决方案1】:

这叫做“插值”。

这意味着“messages()”被转义了,例如如果您有以下代码:

var randomText = '<p> this is a <strong>text</strong></p>'
p= randomText

通常,未转义,会产生它的本来面目:

'<p> this is a <strong>text</strong></p>'

但是如果我输入这个:

p!= randomText

它实际上会变成一个 p 标签,看起来就像这样:

这是一个文本

希望对你有帮助:-)

您可以在此处阅读更多有关文档的信息:https://pugjs.org/language/interpolation.html

【讨论】:

  • 我认为您可能会倒退,我相信 != 意味着它是 NOT 转义的(例如,按字面解释字符串)并且没有它,字符将自动被逃脱
【解决方案2】:

你应该试试

if(!messages())
 table(class='table table-striped')

您必须在左侧分配一些值。否则只需验证到 if 条件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 2018-01-23
    • 2017-01-17
    • 2017-06-27
    相关资源
    最近更新 更多