[英]Set the prohibition on editing the field in Ext.window.Window provided
我需要在Ext.window.Window中設置禁止編輯文本字段的條件,前提是下拉列表的值設置為“推遲”。
我正在嘗試在filterCombo函數中執行以下操作:
var inp = this.up ('window'). down ('# MyTextField');
inp.disable ();
但是在控制台中出現錯誤:TypeError:this.up不是函數
我究竟做錯了什么? 下面是我的代碼:
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();
您不能在select函數的范圍之外使用“ this”,您已經將“ this”作為參數“ combobox”傳遞了,所以像這樣使用它:
function filterCombo(combobox, records) {
var inp = combobox.up('window').down('#MyTextField');
if(records.data.name == 'Postponed'){
inp.disable();
} else {
inp.enable();
}
...
在定義filterCombo方法時,將其視為全局范圍。 這就是為什么沒有this.up的原因,因為這是全局的。
為了使代碼正常工作,您需要在調用函數時傳遞范圍,只需替換
listeners: {
select : function(combo, records) {
filterCombo(combo, records);
}
}
與
listeners: {
select : function(combo, records) {
filterCombo.apply(this,[combo, records]);
}
}
請注意,使用apply可以更改方法中的行為。
解:
function filterCombo(combobox, records) {
if (records.data.name == 'Postponed'){
var inp = combobox.up('window').getComponent('MyTextField');
console.log(inp);
inp.disable();
}
...
});
說明:
您要做的是獲取對textfield
引用,然后將其禁用。
texfield
配置使用itemId
,因此您必須使用texfield的容器getComponent()
方法 textfield
容器,請使用combobox.up('window')
,而不要使用this.up('window')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.