代码之家  ›  专栏  ›  技术社区  ›  Nuri Engin

ExtJS:如何在函数中更改组件“labelStyle”?

  •  1
  • Nuri Engin  · 技术社区  · 6 年前

    tl/dr公司 : 根本没有 setter labelStyle . 那么我怎样才能改变函数的值呢?

    我有一个 afterrender 倾听者和目标设定的颜色 fieldLabel emptyText 而不是 字段标签 lableStyle 财产。我试着进去 config 但是找不到。也试着用 Ext.apply()

    //Related component `listeners`;
    listeners   : {
            afterrender: 'removeLabel',
            focusenter: 'createLabel'
        },
    
    //Related function;
    removeLabel: function () {
            let formComponent = ['foocombobox', 'bartextfield', 'zetdatefield'];
    
            Ext.each(formComponent, function (eachComp) {
                let currentComp = Ext.ComponentQuery.query(eachComp)[0];
    
                if (currentComp.value === '')) {
                    let currentLabel = currentComp.fieldLabel;
                    currentComp.setEmptyText(currentLabel);
    
                    //This can not work because of I've reach constructor config. So how can I reach?
                    //currentComp.labelStyle  = "color:red;";
    
                    //I tried to manipulate through Ext.apply but did not effect;
                    //Ext.apply(currentComp, {labelStyle: "color:red;"});
    
    
                }
            });
        }, 
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   beso9595 Spring boots    6 年前

    我得到了dom节点 currentComp.labelTextEl.dom 然后跑 setAttribute 功能:

    FIDDLE

    if (!currentComp.value) {
        urrentComp.setEmptyText(currentComp.fieldLabel);
        currentComp.labelTextEl.dom.setAttribute('style', 'color:white;'); 
    }