javascript - 在提供的 Ext.window.Window 中设置禁止编辑字段
问题描述
我需要设置禁止编辑 Ext.window.Window 中的文本字段,前提是下拉列表的值设置为推迟。
我正在尝试在 filterCombo 函数中执行此操作:
var inp = this.up ('window'). down ('# MyTextField');
inp.disable ();
但在控制台中我收到错误:TypeError: this.up is not a function
我究竟做错了什么?下面是我的代码:
var store = Ext.create('Ext.data.Store', {
fields: ['order', 'id', 'name'],
storeId: 'DoubleBookStore',
data : [
{"id": 23, name: "New", order_install: 1},
{"id": 24, name: "In Work", order_install: 2},
{"id": 29, name: "Postponed", order_install: 3},
{"id": 34, name: "Shipped", order_install: 4},
{"id": 31, name: "In_transit", order_install: 5}
]
});
function filterCombo(combobox, records) {
if(records.data.name == 'Postponed'){
var inp = this.up('window').down('#MyTextField');
console.log(inp);
inp.disable();
}
index = records.data.order_install;
store = combobox.getStore();
store.clearFilter();
store.filterBy(
function(record) {
if ((record.internalId == index - 1) || (record.internalId == index) || (record.internalId == index + 1)) {
return true;
} else {
return false;
}
}
);
};
var window = Ext.create('Ext.window.Window', {
title: 'Приложение',
width: 300,
height: 200,
items:[{
xtype: 'combobox',
fieldLabel: 'Status',
name: 'status',
store: store,
valueField: 'id',
displayField: 'name',
typeAhead: true,
queryMode: 'local',
value: 24,
listeners: {
select : function(combo, records) {
filterCombo(combo, records);
}
}
},
{
xtype: 'textfield',
fieldLabel: 'Ваше имя:',
itemId:'MyTextField',
name: 'name'
}]
});
window.show();
解决方案
当您在定义时定义 filterCombo 方法时,它将 this 作为全局范围。这就是为什么没有 this.up 的原因,因为这里是全局的。
要使您的代码正常工作,您需要在调用函数时传递范围,只需替换
listeners: {
select : function(combo, records) {
filterCombo(combo, records);
}
}
和
listeners: {
select : function(combo, records) {
filterCombo.apply(this,[combo, records]);
}
}
注意在你的方法中使用 apply 来改变 this 的行为。
推荐阅读
- swift - 如何修复 WatchOS Dock/App Switcher 中缺少的应用程序图标
- android-studio - 什么是“build.gradle.in”文件?
- java - 如何使用 Java 代码将图像转换为数组?
- port - 如何更改 svelte 中的默认端口 5000?
- excel - 从Hexa转换为Binary Excel VBA大量的代码
- javascript - 如何在 React.js 中添加指向这些按钮的链接
- c++ - HLSL 将着色器拆分为多个文件
- python-3.x - 多个逻辑语句是否在单个 while 循环中工作?
- mongodb - MongoDB查找作为查询文本的子字符串的字段
- python - 为什么使用 Python 异步从文件读取和调用 API 比同步慢?