【问题标题】:Variable attribute names in jade玉中的变量属性名称
【发布时间】:2013-11-04 19:20:25
【问题描述】:

jade中可以有变量属性名吗?我想创建一个具有不同属性名称的 mixin:

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

如果这可以循环完成也会很好:

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

【问题讨论】:

    标签: javascript pug


    【解决方案1】:

    想出了这个:

    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'})
    

    结果:

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

    【讨论】:

    • 嗯,这只是为我输出 。自从回答了这个问题后,Jade 的渲染方式会发生变化吗?
    • 但如果我将最后一行更改为以下内容,它会起作用!按钮和属性(属性)!{button_text}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    • 1970-01-01
    相关资源
    最近更新 更多