简体   繁体   English

extJS:通过JS在字段上设置“配置选项”

[英]extJS: set 'config options' on field by JS

why i can't set ' Config options ' by methode SET 为什么我不能通过SET方法设置' Config options '

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. 使用对象重置组件属性不是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. config用于对象创建,当首次在构造函数中使用config时,将使用Extjs类系统核心的特殊方法将其应用于对象本身,以生成getter和setter,然后从它们中初始化组件。 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. 在上面的示例中,使用配置初始化文本字段,该文本字段在创建过程中覆盖了组件的默认值,然后为某些属性(例如value,id和fieldLabel)生成了getter和setter,在使用a之后,这些属性需要代替配置对象使用组件已创建。 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);
        }]
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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