我有一个默认设置为禁用的字段。但我想在单击按钮时更改此属性(启用它)。
{
margin: '10 50 10 50',
padding: '10 20 10 20',
xtype: 'textfield',
name: 'name',
fieldLabel: 'Survey Name',
allowBlank: false,
disabled: true,
id: 'name'
},
这是按钮:
{
margin: '0 50 0 50',
padding: '10 20 10 20',
xtype: 'button',
text: "Create",
listeners: {
click: function() {
Ext.get('name').disabled = false;
}
}
}
当我点击这个时,什么也没有发生。这里有什么问题?
因为您已经为您的组件提供了
id
,所以不要通过Ext.get()
使用Ext.getCmp()
.
例子
Ext.getCmp('name').setDisabled(false)
在这个Fiddle中,我使用相同的代码创建了一个演示。
代码片段:
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create({
xtype: 'panel',
title: 'Demo',
renderTo: Ext.getBody(),
layout: 'hbox',
bodyPadding: 10,
items: [{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Survey Name',
allowBlank: false,
disabled: true,
id: 'name'
}, {
xtype: 'button',
text: "Create",
listeners: {
click: function () {
Ext.getCmp('name').setDisabled(false);
}
}
}]
})
}
});
注意:不要使用
id
,而是使用 itemId
或 extjs 组件的任何其他配置,因为 id 不能重复。所以你也可以这样做
代码片段:
Ext.create({
xtype: 'panel',
title: 'Enable component using ITEM ID',
renderTo: Ext.getBody(),
layout: 'hbox',
bodyPadding: 10,
items: [{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Survey Name',
allowBlank: false,
disabled: true,
itemId: 'name'
}, {
xtype: 'button',
text: "Create",
handler: function() {
this.up('panel').down('#name').setDisabled(false);
}
}]
})
关于Ext JS的资料太少了
我试过了,要删除
disabled
属性,您可以使用Ext.dom.Element
的“设置”功能,第二个参数为false
.
Ext.get('name').set({'disabled': false }, false);
但我想你可以使用旧版本的 Ext JS。 在最新版本中,可以使用
value === undefined
删除它