扩展对象以在Jade中设置属性 [英] Expanding an object to set attributes in Jade

查看:121
本文介绍了扩展对象以在Jade中设置属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够传入带有表示元素属性的键/值对的对象.翡翠有可能吗?

I would like to be able to pass in an object with key/value pairs that represent attributes for an element. Is this possible with Jade?

任何允许我将属性集合传递到模板中的解决方案就足够了,但是将显式声明的属性与从对象提取的属性(如下所示)混合的能力将是理想的.

Any solution that allows me to pass an attributes collection into my template would be sufficient, but the ability to mix explicitly declared attributes with attributes extracted from an object (as below) would be ideal.

以下语法不起作用,它只是我想做的一个例子.

例如,如果我通过了此操作:

For example, if I passed this:

{ 
    name:'username',
    value:'bob',
    attributes: {
        maxlength: 16
    }
}

此模板:

input(name=name, value=value, attributes)

所需的输出将是:

<input name="username" value="bob" maxlength="16" />

推荐答案

由于您是 在GitHub上发布,您可能已经知道答案了.但是,对于其他人,这是答案:

Since you are a part of this issue on GitHub, you probably already know the answer. But, for anyone else, here is the answer:

玉:

input.foo(name=name value=value)&attributes(attrs)

将此数据传递到渲染函数:

Pass this data to your render function:

{
    name: 'username',
    value: 'bob',
    attrs: {
        maxlength: 16
    }
}

输出:

<input name="username" value="bob" class="foo" maxlength="16"/>

这篇关于扩展对象以在Jade中设置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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