使用ext js 3.3对'textfield'进行readonly条件调整

时间:2012-06-25 08:20:00

标签: extjs extjs3

我正在使用ExtJS 3.3,我的formpanel

代码如下
Ext.apply(this, {
    items: [{
            xtype: 'textfield',
            fieldLabel: 'ApplicationGUID',
            labelAlign: 'right',
            name: 'Application_GUID',
            value: 0,
            readOnly: false,
            width: 300
        },
        {
            xtype: 'textfield',
            fieldLabel: 'ApplicationName',
            labelAlign: 'right',
            name: 'Application_Name',
            anchor: '-20',
            msgTarget: 'side'
        }

    ], //eof items
    tbar: [{
        xtype: 'mydeletebutton',
        scope: this,
        ownerCt: this,
        handler: this.deleteHandler,
        myAuth: {
            compBaseRights: {
                Delete: {
                    failProperty: {
                        disabled: false
                    }
                } /*eof Delete*/
            } /*eof compBaseRights*/
        } /*eof sgAuth*/
    }, {
        xtype: 'tbseparator'
    }, {
        xtype: 'trashcanbutton',
        scope: this,
        ownerCt: this,
        handler: this.setIsDeletedHandler,
        myAuth: {
            compBaseRights: {
                Insert: {
                    failProperty: {
                        disabled: false
                    }
                } /*eof Delete*/
            } /*eof compBaseRights*/
        }
    }, {
        xtype: 'mytrashcanrestorebutton',
        scope: this,
        ownerCt: this,
        handler: this.unsetIsDeletedHandler,
        myAuth: {
            compBaseRights: {
                Insert: {
                    failProperty: {
                        disabled: false
                    }
                } /*eof Delete*/
            } /*eof compBaseRights*/
        }
    }, {
        xtype: 'tbseparator'
    }, {
        xtype: 'mysavebutton',
        scope: this,
        handler: this.saveHandler,
        myAuth: {
            compBaseRights: {
                Write: {
                    failProperty: {
                        disabled: false
                    }
                } /*eof Delete*/
            } /*eof compBaseRights*/
        }
    }],
    bbar: {
        xtype: 'mystatusbar'
    }
});

我正在寻找的是textfield Application_GUID,如果某个值已经存在,我需要readOnly: true(比如当我从网格中双击现有的一个以便编辑时)它),如果我按下grid中的新按钮,我需要readonly语句为false

如果有人可以帮助我,那将会感激不尽。感谢。

1 个答案:

答案 0 :(得分:1)

一个好的技术是将布尔变量设置为初始化为false。然后根据您的需要将其设置为true。

然后添加所需的侦听器,如以下示例代码中所示,例如在更改侦听器上:

listeners: {
    yourlistener: function(e) { //yourlistener can be change, select, etc...
        if (booleanVariable === true) Ext.getCmp('your-textbox-id').setReadOnly(true);
        else Ext.getCmp('your-textbox-id').setReadOnly(false);
    }
 }