我有一个组件如下:
{
xtype: 'fieldcontainer',
layout: 'hbox',
id: 'article-level-container',
defaultType: 'textfield',
fieldDefaults: {
labelAlign: 'top'
},
items: [{
fieldLabel: 'LEVEL',
name: 'artLevel',
inputWidth: 216,
margins: '0 5 5 0',
allowBlank: false,
fieldStyle: 'text-align: right; font-size: 13pt; background-color: #EAFFCC;'
}, {
fieldLabel: 'VALUE',
name: 'artValue',
inputWidth: 216,
allowBlank: false,
blankText: 'zorunlu alan, boş bırakılamaz',
fieldStyle: 'text-align: right; font-size: 13pt; background-color: #EAFFCC;',
listeners: {
change: function(textfield, newValue, oldValue) {
if (oldValue == 'undefined' || newValue == '') {
Ext.getCmp('btnArticleSave').disable();
} else {
Ext.getCmp('btnArticleSave').enable();
}
}
}
}]
}
我想获取第二项 fieldLabel
值(在本例中为 VALUE)。
- 如何在
onReady
函数之外获取此字段值? - 如何用新值更改此字段标签(我想用选定的组合框值更改字段标签)
更新 我尝试了以下操作:
var artField = Ext.ComponentQuery.query('#articleValueField');
console.log(artField);
最佳答案
一些常用的方法是使用 Ext.ComponentQuery
:
在其配置中为您的字段提供一个 itemId
,例如itemId: 'theField'
:
var field= Ext.ComponentQuery.query('#theField')[0];
field.setFieldLabel(valueFromCombo);
在你的组合中添加一个 on change
监听器,你可以使用 up 和 down(这也是组件查询)
listeners: {
change: function(combo) {
var form = combo.up('#form');
var field = form.down('#theField');
field.setFieldLabel(lookupValueFromCombo);
}
}
请记住,ext js 中的任何配置设置都将获得 setter 和 getter,因此 fieldLabel
具有 getFieldLabel()
和 setFieldLabel(s)
方法.
编辑 以上仅适用于 ext js 4.1+ 使用 ext js 4.0+,您可以:
field.labelEl.update('New Label');
关于javascript - ExtJS - 如何获取组件项值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17670976/