-
30 Jan 2012 4:36 AM #1
Loader problem with requires
Loader problem with requires
I'm trying to use "requires" to load missing parts in a component, but I get an error when the class is not loaded explicitly with Ext.require (these components are seldom used, so I don't want to load them each time for all users, just only when needed).
I have tested the following code with 4.0.7 and 4.1b2, but they both fail with the error "Cannot call method 'substring' of undefined"
When uncommenting the Ext.require() line or not using the requires option at all, the grid loads without problems.Code:Ext.Loader.setConfig({ enabled:true, paths:{ 'Ext.ux':'/extjs/examples/ux' } }); // Ext.require("Ext.ux.CheckColumn"); Ext.onReady(function() { Ext.define('Ext.app.Grid', { extend: 'Ext.grid.Panel', requires:['Ext.ux.CheckColumn'], alias: "widget.mygrid", width: 300, store: { fields:['name', 'mark'], data:[ { 'name':'Lisa', "mark":true }, { 'name':'Bart', "mark":true }, { 'name':'Homer', "mark":false }, { 'name':'Marge', "mark":false } ] }, columns:[ { header:'Name', dataIndex:'name', flex:1 }, { header:'Mark?', dataIndex:'mark', xtype:'checkcolumn'} ] }); Ext.widget("mygrid", {renderTo: Ext.getBody()}); });
Am I missing something or is there a problem in the loader?
Regards,
Quico
-
30 Jan 2012 7:27 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,641
- Vote Rating
- 434
You shouldn't use Ext.define within onReady. Using b1, this works with no problems for me:
Code:Ext.Loader.setConfig({ enabled:true, paths:{ 'Ext.ux':'SDK/extjs/examples/ux' } }); Ext.require("Ext.ux.CheckColumn"); Ext.define('Ext.app.Grid', { extend: 'Ext.grid.Panel', requires:['Ext.ux.CheckColumn'], alias: "widget.mygrid", width: 300, store: { fields:['name', 'mark'], data:[ { 'name':'Lisa', "mark":true }, { 'name':'Bart', "mark":true }, { 'name':'Homer', "mark":false }, { 'name':'Marge', "mark":false } ] }, columns:[ { header:'Name', dataIndex:'name', flex:1 }, { header:'Mark?', dataIndex:'mark', xtype:'checkcolumn'} ] }); Ext.onReady(function() { Ext.widget("mygrid", {renderTo: Ext.getBody()}); });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
2 Feb 2012 3:15 AM #3
Hi,
Yes, the example works as intented with that modification, but my code, which is way more complex, is still no working. I'm very busy these days, so I can not extract another test that fails. I'll come back later when I have some more time to debug.
Thanks.
-
2 Feb 2012 7:47 AM #4
OK, I think I found the failing case: just add a new class that inherits from Ext.app.Grid:
Code:Ext.Loader.setConfig({ enabled:true, paths:{ 'Ext.ux':'SDK/extjs/examples/ux' } }); Ext.require("Ext.ux.CheckColumn"); Ext.define('Ext.app.Grid', { extend: 'Ext.grid.Panel', requires:['Ext.ux.CheckColumn'], alias: "widget.mygrid", width: 300, store: { fields:['name', 'mark'], data:[ { 'name':'Lisa', "mark":true }, { 'name':'Bart', "mark":true }, { 'name':'Homer', "mark":false }, { 'name':'Marge', "mark":false } ] }, columns:[ { header:'Name', dataIndex:'name', flex:1 }, { header:'Mark?', dataIndex:'mark', xtype:'checkcolumn'} ] }); Ext.define('Ext.app.Grid2', { extend: ['Ext.app.Grid'] }); Ext.onReady(function() { Ext.widget("mygrid", {renderTo: Ext.getBody()}); });


Reply With Quote