tl / dr:setter
没有任何labelStyle
。那么如何更改函数的值呢?
我有一个afterrender
侦听器,旨在将fieldLabel
的颜色设置为白色,并设置emptyText
而不是fieldLabel
,同时我需要将fieldLabel
的颜色更改为白色!因此,我需要访问当前组件的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;"});
}
});
},
最佳答案
我通过currentComp.labelTextEl.dom
获取dom节点,然后运行setAttribute
函数:
FIDDLE
if (!currentComp.value) {
urrentComp.setEmptyText(currentComp.fieldLabel);
currentComp.labelTextEl.dom.setAttribute('style', 'color:white;');
}