javascript - 如何删除 Ext JS 中的禁用属性
问题描述
我有一个默认设置为禁用的字段。但我想在单击按钮时更改此属性(启用它)。
{
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()
use获取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);
}
}
}]
})
}
});
注意:不要使用extjs 组件id
的itemId
或任何其他配置,因为 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);
}
}]
})
推荐阅读
- inno-setup - 如何在 ShellExec 行中用其常量替换目录
- django - 试图在帖子列表 Django 模板中获得用户的平均评分
- c++ - 初学者问题:如何访问此变量?
- javascript - D3.js在每2条之后绘制垂直线并在条形图顶部绘制x轴标签
- ios - 如何设置相机视图旋转(不使用不推荐使用的代码)
- android - 即使在指定 pageSize=100 之后,NewsApi 也会返回 totalResults=20
- reactjs - 使用 immutableJS 更新对象内部的数组不起作用
- javascript - 使用 rAmCharts 的动画仪表图
- centos7 - OpenNebula 5.6.1 没有这样的文件或目录 - /var/lib/one/config
- node.js - Agenda js:如果我的服务器在作业的预定时间停机会发生什么?