javascript ExtJS - 如何获取组件项值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17670976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 09:08:27  来源:igfitidea点击:

ExtJS - How to get component item value

javascriptextjs

提问by O?uz ?elikdemir

I have a component as follow :

我有一个组件如下:

{
    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();
                }
            }
        }
    }]
} 

I want to get second item fieldLabelvalue ( in this case VALUE ).

我想获得第二个项目fieldLabel值(在本例中为 VALUE )。

  • How can I get this field value outside the onReadyfunction?
  • How can I change this field label with new value ( I want to change fieldlabel with selected combobox value )
  • 如何在onReady函数之外获取此字段值?
  • 如何使用新值更改此字段标签(我想使用选定的组合框值更改字段标签)

UPDATEI tried the following :

更新我尝试了以下操作:

var artField = Ext.ComponentQuery.query('#articleValueField');
console.log(artField);

Console Output

控制台输出

回答by jenson-button-event

A few ways but common is to use Ext.ComponentQuery:

有几种方法但常见的是使用Ext.ComponentQuery

Give your field an itemIdin its config e.g. itemId: 'theField':

itemId在它的配置中给你的字段一个,例如itemId: 'theField'

 var field= Ext.ComponentQuery.query('#theField')[0];
 field.setFieldLabel(valueFromCombo);

Add an on changelistener to your combo, you can use up and down (which are also component queries)

change为您的组合添加一个 on侦听器,您可以使用 up 和 down (这也是组件查询)

listeners: {
  change: function(combo) {
    var form = combo.up('#form');
    var field = form.down('#theField');
    field.setFieldLabel(lookupValueFromCombo);
  }
}

Remember any config settings in ext js will get a setter and getter, thus fieldLabelhas getFieldLabel()& setFieldLabel(s)methods.

记住 ext js 中的任何配置设置都会得到一个 setter 和 getter,因此fieldLabelgetFieldLabel()&setFieldLabel(s)方法。

editabove is only with ext js 4.1+ with ext js 4.0+ you can do:

上面的编辑仅适用于 ext js 4.1+ 和 ext js 4.0+,您可以执行以下操作:

field.labelEl.update('New Label');

回答by Ahmed MEZRI

to get the combobox selected item outside the combo listener

在组合侦听器之外获取组合框所选项目

yourComboboxName.on('change', function (combo, record, index) {

            alert(record);  // to get the selected item

            console.log(record);  // to get the selected item

        });