【问题标题】:How can I concatenate an array in jade?如何在玉中连接数组?
【发布时间】:2018-07-09 18:40:38
【问题描述】:

我正在尝试使用 for 循环连接数组 c[x].topLevelIndustry 中的项目:

 -var text="";
 -var y;
 script.
   for (y=0, y< c[x].topLevelIndustry.length, y++){
     text+=#{c[x].topLevelIndustry[y]} + ",";
   }
 p= text
  1. 如何解决这个问题,我尝试了多种方法?
  2. jade/javascript中变量之间的关系是什么?如果我设置了-var somevar,那么我如何使它可用于玉?

【问题讨论】:

    标签: javascript pug


    【解决方案1】:

    使用 script 标签可以防止 pug 运行代码。相反,它被传递给浏览器以在客户端执行。使用unbuffered code block,而不是脚本标签。

    -
      var text = "";
      var y;
      for (y = 0, y < c[x].topLevelIndustry.length, y++){
        text += c[x].topLevelIndustry[y] + ",";
      }
    
    p #{text}
    

    使用.join() javascript method 可以更简洁地实现相同的结果。

    p= c[x].topLevelIndustry.join()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-05
      • 2015-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-09
      相关资源
      最近更新 更多