在用Extjs进行网页开发的时候,遇见了一下两个错误,这两个错误的位置用firebug调试显示在extjs-all.js
Ext.resetElement is undefined
g.el is null
其实这与extjs-all.js完全无关,因为有时候你在js代码里少打了个","号,extjs认不出来,也会显示错误在extjs-all.js
那么这两个错误怎么解决呢?
经过用Google搜索,终于在Stackoverflow,得到了一个正确答案。
Make sure you are using Ext.onReady(function() { ... })
. ExtJS uses Ext.resetElement
which is set before onReady
call.
也就是在把extjs代码写在Ext.onReady(function() { ...extjs代码.. });里。
问题果然解决了。
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错误,导致面板无法正常显示。