Can you refer to variables with dashes in jade?(您可以在玉中引用带有破折号的变量吗?)
问题描述
我正在尝试在我的翡翠模板中做这样的事情
I'm trying to do something like this in my jade template
a.apply-url(href="#{apply-url}")
但它被解释为应用减去 url"
But it's being interpreted as 'apply minus url'
有没有办法强制解释器做正确的事情?或者有什么方法可以引用顶级对象,并将索引放在引号中,像这样?
Is there a way I can force the interpreter to do the right thing? Or is there some way to refer to a top-level object, and put the index in quotes, like this?
a.apply-url(href="#{this['apply-url']}")
推荐答案
我对 Jade 不是很熟悉,但我之前研究过一点.在 here 玩了一段时间后,我能够让它工作:
I'm not all that familiar with Jade, but I have looked into it a little bit before. After playing around a while here, I was able to get this to work:
a.apply-url(href="#{locals['apply-url']}")
{"apply-url": "foo"}
产生:
<a href="foo" class="apply-url"></a>
这是可行的,因为这个特定的实现将数据存储在名为 locals
的局部变量中,然后由模板函数关闭.据我所知,这是一个实现细节,我不一定期望它在其他 Jade 实现中也能工作.
This works because this particular implementation stores the data in a local variable named locals
which is then closed over by the templating function. As far as I can tell, this is an implementation detail, and I wouldn't necessarily expect this to work in other Jade implementations.
这篇关于您可以在玉中引用带有破折号的变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:您可以在玉中引用带有破折号的变量吗?
基础教程推荐
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01