繁体   English   中英

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

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

为什么我不能通过SET方法设置' Config options '

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

我如何为字段设置“属性”

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

使用对象重置组件属性不是Extjs设计的一部分。 config用于对象创建,当首次在构造函数中使用config时,将使用Extjs类系统核心的特殊方法将其应用于对象本身,以生成getter和setter,然后从它们中初始化组件。 无法做您想做的事情并获得期望的结果。 在上面的示例中,使用配置初始化文本字段,该文本字段在创建过程中覆盖了组件的默认值,然后为某些属性(例如value,id和fieldLabel)生成了getter和setter,在使用a之后,这些属性需要代替配置对象使用组件已创建。 为了使示例工作,您需要执行以下操作:

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