Sencha - 向元素添加自定义属性

时间:2012-03-06 07:15:55

标签: attributes extjs

我希望我的div看起来像这样

<div id="example" customAtt="try"></div>

如何在sencha中为面板,按钮等添加自定义属性?

谢谢

3 个答案:

答案 0 :(得分:0)

如果是Ext.Component,可以进行如下操作

listeners: {
    afterrender: function (component) {
        component.getEl().dom.setAttribute("myCustomAttribute", "SOME_VALUE");
    }
}

答案 1 :(得分:0)

您可以在经典框架中使用 autoEl:

Ext.create({
    xtype: 'component',
    renderTo: Ext.getBody(),
    html: 'Hi !!!',
    id: "example",
    autoEl: {
        customAtt: "try"
    }
});

板条箱...

<div class="x-component x-component-default x-border-box" customatt="try" id="example">Hi !!!</div>

答案 2 :(得分:-1)

您可以轻松添加自定义属性,与定义配置属性的方式相同。

    mycont = {
        xtype: 'container',
        id: 'cont123',
        width: 300,
        height: 100,
        customAttribute1: customAttribute1Value
        customAttribute2: customAttribute2Value
        ...
    }
相关问题