【问题标题】:EXTJS Window/Panel close errorEXTJS 窗口/面板关闭错误
【发布时间】:2016-03-03 17:38:31
【问题描述】:

我正在创建一个新的 EXTJS 窗口,在该窗口内有一个面板,在该面板内有一个表单!

当我单击“X”或取消关闭窗口时,我收到此错误:

Uncaught TypeError: Cannot read property 'className' of undefinedhasClass
@ ext-all-debug.js:2252addClass
@ ext-all-debug.js:2183Ext.Button.Ext.extend.onMouseOver
@ ext-all-debug.js:31140aK
@ miframe.js:1

我在取消按钮中使用这个处理程序:

handler: function () {
    this.close();
},

完整代码-

example.SurveyFieldDefaultWindow = Ext.extend(Ext.Window, {

id: 'survey-default-win',
title: 'Custom Survvey',
modal: true,
closable: true,
width: 500,
height: 600,
frame: true,
bodyStyle: 'padding: 5px',
forceFit: true,
constrainHeader: true,
layout: 'fit',
initComponent: function () {
    this.canEdit = this.checkEditPermissions();
    questionStore2 = questionStore;


    var survey_window = Ext.getCmp('survey-win');
    survey_window.afterRender(
        survey_window.getFormValues()
    );

    formValues2 = formValuesObj;

     survey_default_id = Math.floor(10000 + Math.random() * 90000);

    Ext.apply(
        this, {
            items: [{
                xtype: 'tabpanel',
                id: 'survey-field-form-tabpanel',
                layoutOnTabChange: true,
                activeTab: 0,
                items: [{
                    title: 'Questions',
                    layout: 'fit',

                    items: [{
                        xtype: 'form',
                        id: 'survey-field-form',
                        border: false,
                        bodyStyle: 'padding: 5px;',
                        frame: true,
                        defaultType: 'textfield',

                    }]
                }]
            }],
            buttons: [{
                id: 'save-button',
                text: 'Default-Save',
                handler: function () {
                    this.saveForm()
                },
                scope: this
            }, {
                text: 'Default-Cancel',
                handler: function () {
                    this.close();

                },
                scope: this
            }]

        }
    );
    example.SurveyFieldDefaultWindow.superclass.initComponent.apply(this, arguments);

    var data = questionStore2.data.items;

    for (var i = 0; i < data.length; i++) {
        if (data[i].data.fieldTypeName == "DropDownList" || data[i].data.fieldTypeName == "RadioButtonList" || data[i].data.fieldTypeName == "CheckBoxList" || data[i].data.fieldTypeName == "Rating" || data[i].data.fieldTypeName == "YesNo") {
            // create a Record constructor:
            var rt = Ext.data.Record.create([
                {name: 'optionValue'},
                {name: 'optionText'}
            ]);
            var myStore = new Ext.data.Store({
                // explicitly create reader
                reader: new Ext.data.ArrayReader(
                    {
                        idIndex: 0  // id for each record will be the first element
                    },
                    rt // recordType
                )
            });
            var myData = [];

            for (var j = 0; j < data[i].data.selectOptions.list.length; j++) {

                var optionText = data[i].data.selectOptions.list[j].optionText.toString();
                var optionValue = data[i].data.selectOptions.list[j].optionValue.toString();

                myData.push([optionValue, optionText]);

            }

            myStore.loadData(myData);

            var id = data[i].data.name.toString();
            var cb = new Ext.form.ComboBox({
                fieldLabel: data[i].data.name,
                id: id,
                typeAhead: true,
                allowBlank: true,
                mode: 'local',
                emptyText: 'Select Default value',
                width: 190,
                margin: '40 30 20 10',
                store: myStore,
                valueField: 'optionValue',
                displayField: 'optionText',
                selectOnFocus: true,
                triggerAction: 'all',
                listeners: {
                    'select': function (cb, newValue, oldValue) {

                        for (var i = 0; i < formValues2.fields.list.length; i++)
                        {
                            for (var j = 0; j < formValues2.fields.list[i].selectOptions.list.length; j++)
                            {

                                if(formValues2.fields.list[i].name == cb.fieldLabel ){
                                    if( formValues2.fields.list[i].selectOptions.list[j].optionText == cb.lastSelectionText) {
                                        formValues2.fields.list[i].selectOptions.list[j].preselect = true;
                                    }

                                }
                            }
                        }
                    }
                }
            });
            Ext.getCmp('survey-field-form').add(cb);
            Ext.getCmp('survey-field-form').doLayout();

        }
    }


    getDefaultSurveyFormValues = Ext.getCmp('survey-field-form');
    getDefaultSurveyFormValues.on("afterrender", function () {
        //this code will run after the panel renders.
        if (getDefaultSurveyFormValues != undefined) {
            getDefaultSurveyFormValues.getForm().getValues();

        }
        else {
            console.log('undefined getDefaultSurveyFormValues');
        }
    });


},
checkEditPermissions: function () {
    return Security.hasAccess("Surveys", Security.UPDATE_ACCESS);
},

saveForm: function () {

    // disable save button while saving form
    // Ext.getCmp('save-button').disable();             ----------------------------------- undo comment later
    // submit the form using a jabsorb call


    Ext.getCmp('survey-field-form').getForm().doAction("JabsorbSubmit", {
        formValues: formValues2,
        jabsorbMethod: Jabsorb.getInstance().surveyTemplateService.saveSurveyTemplate,
        //   timeout:300000,
        failure: function (form, action) {
            Ext.Msg.alert('Request Failed', 'Could not save survey template information to generate Survey View: ' + action.result.msg);
        },
        success: function (form, action) {
            Ext.Msg.alert('magic' , 'magic');

        }
    });
}
});

Ext.reg('example.SurveyFieldDefaultWindow', example.SurveyFieldDefaultWindow);

【问题讨论】:

  • 请编辑您的问题以包含处理程序周围的所有代码。
  • @jsve 包含代码

标签: javascript extjs


【解决方案1】:

根据您的代码创建窗口并使用关闭按钮,我做了一个小提琴。在这里查看:https://fiddle.sencha.com/#fiddle/16lu

据我所知,在您的 initComponent: function() { 中,您永远不会调用 this.callParent() 方法。如果您使用initComponent 配置,则对于类继承非常重要。

来自文档:

调用当前方法的“父”方法。就是这个方法 先前被派生或覆盖覆盖(参见 分机定义)。

【讨论】:

    【解决方案2】:

    在这个范围内,this 代表按钮而不是窗口,所以你试图关闭按钮

    【讨论】:

    • 但是当我使用 Windows 'X' 关闭窗口时出现同样的错误?如何更改范围以表示窗口? Ext.getCmp('survey-default-win'); ?
    • 你能用 Ext.getCmp('survey-default-win').close() 吗?
    • 没试过,让我试一试,但我不明白为什么我在使用 Windows 'X' 关闭按钮时会出现同样的错误
    • 对我来说也很奇怪。您确定您的代码有效吗,我的意思是,您是否忘记了分号、括号或其他内容。我看到你在这里漏掉了一个分号: handler: function () { this.saveForm(); }, 此处多加逗号:defaultType: 'textfield',
    • 好吧,我认为我的代码是有效的,因为其他一切似乎都可以正常工作,只有关闭窗口才会出现错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多