简体   繁体   English

玉器中的变量属性名称

[英]Variable attribute names in jade

Is it possible to have a variable attribute name in jade? 玉器中是否可以使用可变属性名称? I want to create a mixin that will have different name for the attributes: 我想创建一个混合名称,该混合名称将具有不同的属性名称:

mixin button_post(test)
    button(
            #{test.name}='#{test.value}'
    )

Would also be nice if this could be done in a loop: 如果可以循环执行,那也很好:

mixin button_post()
    button(
        each key, value in {one: 'one', two: 'two', three: 'three'}
            #{key}='#{value}'
    )

Figured this one out: 想通了这一点:

mixin test_button(button_text, test)
    each value, key in test
        - attributes[key] = value
    button&(attributes) !{button_text}

+test_button('test', {test: 'test', test2: 'test2'})

Results in: 结果是:

<button test="test" test2="test2">test</button>

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

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