繁体   English   中英

在提供的Ext.window.Window中设置禁止编辑该字段的权限

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM