簡體   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