extjs幾個奇怪的錯誤

在用Extjs進行網頁開發的時候,碰見了一下兩個錯誤,這兩個錯誤的位置用firebug調試顯示在extjs-all.js javascript

Ext.resetElement is undefinedphp

g.el is nulljava

其實這與extjs-all.js徹底無關,由於有時候你在js代碼裏少打了個","號,extjs認不出來,也會顯示錯誤在extjs-all.jsthis

那麼這兩個錯誤怎麼解決呢?url

通過用Google搜索,終於在Stackoverflow,獲得了一個正確答案。spa

Make sure you are using Ext.onReady(function() { ... }). ExtJS uses Ext.resetElementwhich is set before onReady call.調試

也就是在把extjs代碼寫在Ext.onReady(function() { ...extjs代碼.. });裏。code

問題果真解決了。orm

Ext.onReady(function(){
Ext.create('Ext.form.Panel', {
    title: '選擇',
    bodyPadding: 5,
    width: 280,

    // The form will submit an AJAX request to this URL when submitted
   // url: 'save-form.php',

    // Fields will be arranged vertically, stretched to full width
    layout: 'anchor',
    defaults: {
        anchor: '100%'
    },

    // The fields
    defaultType: 'textfield',
    items: [{
        fieldLabel: '車次號',
        name: 'trainno',
        allowBlank: false
    },{
    	
   	 //xtype: 'datepicker',
   	 xtype: 'datefield',
        anchor: '100%',
        fieldLabel: '日期',
        name: 'to_date',
        value: new Date(),  // defaults to today
     maxDate: new Date(),
     handler: function(picker, date) {
         // do something with the selected date
     }
    }
    ],

    // Reset and Submit buttons
    buttons: [{
        text: '重置',
        handler: function() {
            this.up('form').getForm().reset();
        }
    }, {
        text: '確認',
        formBind: true, //only enabled once the form is valid
        disabled: true,
        handler: function() {
            var form = this.up('form').getForm();
            if (form.isValid()) {
                form.submit({
                    success: function(form, action) {
                       Ext.Msg.alert('Success', action.result.msg);
                    },
                    failure: function(form, action) {
                        Ext.Msg.alert('Failed', action.result.msg);
                    }
                });
            }
        }
    }],
    renderTo:"left"
});
});

好比上面這個代碼我若是不加Ext.onReady(function() { ...extjs代碼.. });裏就會報g.el is null錯誤,致使面板沒法正常顯示。blog

相關文章
相關標籤/搜索