EXTJS窗口/面板关闭错误

时间:2016-03-03 17:38:32

标签: javascript extjs

我正在创建一个新的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);

2 个答案:

答案 0 :(得分:3)

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

从我所看到的情况来看,在initComponent: function() {中,你永远不会调用this.callParent()方法。如果使用initComponent config。

,这对于类继承非常重要

来自文档:

  

调用当前方法的“父”方法。这就是方法   以前通过派生或覆盖覆盖(见   Ext.define)。

答案 1 :(得分:0)

在此范围内,this代表按钮而非窗口,因此您尝试关闭按钮