能否在玉器中使用破折号引用变量? [英] Can you refer to variables with dashes in jade?

查看:71
本文介绍了能否在玉器中使用破折号引用变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的翡翠模板中做类似的事情

I'm trying to do something like this in my jade template

a.apply-url(href="#{apply-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并不十分熟悉,但是我之前已经对其进行了研究.在这里玩了一段时间之后,我能够使它工作:

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.

这篇关于能否在玉器中使用破折号引用变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆