gpt4 book ai didi

javascript - 如何连接 Jade 中的数组?

转载 作者:行者123 更新时间:2023-11-29 23:19:32 25 4
gpt4 key购买 nike

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

 -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那我如何让它可用于 Jade ?

最佳答案

使用脚本标签可以防止 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()

关于javascript - 如何连接 Jade 中的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51252100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com