简体   繁体   English

如何在Jade模板中执行JavaScript数学?

[英]How to do javascript math in a jade template?

I want the lightness to be a function of order of item on the list 我希望亮度是列表上项目顺序的函数

Here's the order variable 这是订单变量

{{order}}

Here's the template language I'm trying to modify 这是我要修改的模板语言

.minicard(style="background-color:hsl(354,100%,{{(order * 2)+46}}%)")

What I'm basically trying to do is multiply order by 2 and add 46 to it. 我基本上想做的是将2乘以2,然后加上46。

{{order}} works but doing math within the curly brackets doesn't seem to. {{order}}可以使用,但是似乎无法在大括号内进行数学运算。 How do I do simple javascript in a jade template? 如何在Jade模板中使用简单的javascript?

No need for JavaScript, you can do something like this: 不需要JavaScript,您可以执行以下操作:

- order = 10
- order = order * 2 + 45

.minicard(style="background-color:hsl(354,100%,"+order+"%;")

OR you can do it inline: 或者您可以内联:

- order = 10

.minicard(style="background-color:hsl(354,100%," + (order * 2 + 45) + "%;")

Both should compile into: 两者都应编译成:

<div class="minicard" style="background-color:hsl(354,100%,65%"></div>

See working example here - https://codepen.io/AdamCCFC/pen/pWoxXV 在此处查看工作示例-https: //codepen.io/AdamCCFC/pen/pWoxXV

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM