简体   繁体   中英

extJS: set 'config options' on field by JS

why i can't set ' Config options ' by methode SET

set({value: 'new value',disabled:true});

how i can set 'Properties' for a field

var name = {
    fieldLabel:'Name',
    value: 'Test',
    id:'id-name',
    xtype: 'textfield',
};
this.form= new Ext.FormPanel({
    items:[name],
    buttons: [{
        text   : 'set value',
        handler: function() {
            Ext.getCmp('id-name').set({value: 'new value',disabled:true});
        }]
});

Resetting component properties using an object is not part of the design of Extjs. The config is used in object creation and when first used in the constructor is applied to the object itself using special methods from the Extjs class system core to generate getters and setters and then initialize the component from them. It is not possible to do what you are trying to do and get the desired result. In your example above, the textfield is initialized with your config overriding the default values of the component during creation and then it generates getters and setters for certain attributes, like value, id, and fieldLabel which need to be used instead of config objects after a component is created. To make your example work, you need to do this:

var name = {
    fieldLabel:'Name',
    value: 'Test',
    id:'id-name',
    xtype: 'textfield',
};
this.form= new Ext.FormPanel({
    items:[name],
    buttons: [{
        text   : 'set value',
        handler: function() {
            var myTextField = Ext.getCmp('id-name');
            myTextField.setValue('new value');
            myTextField.setDisabled(true);
        }]
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM