简体   繁体   English

在Jade mixins中继承属性

[英]Inheriting attributes in Jade mixins

Is it possible to have a Jade mixin call pass through the attributes passed to the current mixin? 是否可以通过传递给当前mixin的属性来进行Jade mixin调用? Example: 例:

mixin A()
    A=attributes.x

mixin B()
    +A
    B=attributes.x

+B()(x="test")

It outputs: 它输出:

<A></A>
<B>test</B>

Because the attribute x doesn't get passed through to A . 因为属性x不会传递给A This is desired in most cases. 在大多数情况下,这是需要的。 But in my case, I would like to pass through any attributes passed to B into A , without having to list them a priori (ie +A()(x=attributes.x) . 但就我而言,我想将传递给B所有属性传递到A ,而不必先列出它们(即+A()(x=attributes.x)

Is this possible? 这可能吗?

This question is similar to Passing attributes in a jade mixin But the answer posted there does not work as far as I can tell. 这个问题类似于在玉混合中传递属性,但是据我所知,在那里发布的答案不起作用。

In case someone else stumbles upon this, Forbes Lindesay from the Jade Google group answered the question. 万一有人偶然发现,Jade Google小组的Forbes Lindesay回答了这个问题。 It can be done this way: 可以通过以下方式完成:

mixin A()
  | #{attributes.x}

mixin B()
  +A()&attributes(attributes)

+B()(x=“x”)

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

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