【问题标题】:Losing scope in combobox ExtJS 4.2在组合框 ExtJS 4.2 中失去作用域
【发布时间】:2013-12-20 03:20:45
【问题描述】:

我有一个带有组合框和几个按钮的弹出窗口。这个想法是在组合框中进行选择,然后将选择保存到商店或取消。我以前做过这个,从来没有遇到过任何问题,但是使用这段代码,每当我尝试与组合交互时,我都会得到Uncaught TypeError: Cannot call method 'apply' of undefined。在我看来,ExtJS 正在尝试在组合框上运行用于商店的代码。

我用Ext.create('Account.Window.Reuse');加载弹出窗口

定义:

Ext.define('SimpleAccount', {
    extend: 'Ext.data.Model',
    idProperty: 'AccountID',
    fields: [ {
        name: 'AccountID',
        type: 'int',
        useNull: true
    }, 'Name']
});

var userAccountReuseStore = Ext.create('Ext.data.Store', {
    model: 'SimpleAccount',
    storeId: 'userAccountReuseStore',
    data: [{"AccountID":"1", "Name":"FirstAccount"},
        {"AccountID":"2", "Name":"SecondAccount"},
        {"AccountID":"3", "Name":"ThirdAccount"}]
});

Ext.define('Account.Reuse.ComboBox', {
    extend: 'Ext.form.ComboBox',
    alias: 'widget.accountReuseComboBox',
    initComponent: function(){
        Ext.apply(this, {
            fieldLabel: 'Account',
            displayField: 'Name',
            valueField: 'AccountID',
            queryMode: 'local'
        })
    }
});

Ext.define('Account.Reuse.Fieldset', {
    extend: 'Ext.form.FieldSet',
    alias: 'widget.accountReuseFieldset',
    initComponent: function(){
        Ext.apply(this, {
            items: [
                {
                    xtype: 'label',
                    cls: 'text-important',
                    margin: '0 0 10 0',
                    style: 'display: block',
                    text: 'Only attach an account you have permission to use.  After attaching the account you will not be able to use, remove, or edit it until approved by SCSAM'
                },
                {
                    xtype: 'accountReuseComboBox',
                    store: userAccountReuseStore
                }
            ]
        });
        this.callParent();
    }
});

Ext.define('Account.Reuse.Details', {
    extend: 'Ext.form.Panel',
    alias: 'widget.accountReuseDetails',
    initComponent: function(){
        Ext.apply(this, {
            plain: true,
            border: 0,
            bodyPadding: 5,
            fieldDefaults: {
                labelWidth: 55,
                anchor: '100%'
            },
            layout: {
                type: 'vbox',
                align: 'stretch',
                flex: 1
            },
            items: [
                {
                    xtype: 'accountReuseFieldset',
                    defaults: {
                        labelWidth: 89,
                        anchor: '100%',
                        layout: {
                            type: 'vbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0},
                            align: 'stretch'
                        }
                    },
                    title: 'Details',
                    collapsible: false
                }]
        });
        this.callParent();
    }
});

Ext.define('Account.Window.Reuse', {
    extend: 'Ext.window.Window',
    alias: 'widget.accountWindowReuse',
    initComponent: function(){
        Ext.apply(this, {
            title: 'Account Details',
            width: 400,
            autoShow: true,
            modal: true,
            layout: {
                type: 'fit',
                align: 'stretch'  // Child items are stretched to full width
            },
            items: [{
                xtype: 'accountReuseDetails',
                id: 'attachAccountReuseForm'
            }],
            dockedItems: [{
                xtype: 'toolbar',
                dock: 'bottom',
                ui: 'footer',
                layout: {
                    pack: 'center'
                },
                items: [{
                    minWidth: 80,
                    text: 'Attach',
                    id: 'saveButton',
                    handler: function(){
                        var rec = this.up('accountWindowReuse').down('accountReuseDetails').getValues();
                        var store = Ext.getStore('userAccountReuseAttachStore');
                        store.add(rec);
                        this.up('window').close();
                    }
                },{
                    minWidth: 80,
                    text: 'Cancel',
                    handler: function(){
                        this.up('window').close();
                    }
                }]
            }]
        });
        this.callParent();
    }
});

【问题讨论】:

    标签: javascript extjs combobox extjs4 extjs4.2


    【解决方案1】:

    您似乎忘记了在 Account.Reuse.ComboBox initComponent 函数中调用父级,因此组合框未正确初始化。

    您的 Account.Reuse.ComboBox initComponent 函数应如下所示:

    initComponent: function(){
        Ext.apply(this, {
            fieldLabel: 'Account',
            displayField: 'Name',
            valueField: 'AccountID',
            queryMode: 'local'
        });
        this.callParent();
    }
    

    【讨论】:

    • 哇,我不敢相信我错过了。非常感谢!
    猜你喜欢
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    • 1970-01-01
    • 2015-02-09
    • 2011-08-19
    • 1970-01-01
    相关资源
    最近更新 更多