1. #1
    Ext JS Premium Member frsantos's Avatar
    Join Date
    Dec 2011
    Posts
    3
    Vote Rating
    0
    frsantos is on a distinguished road

      0  

    Default 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"

    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()});
        });
    When uncommenting the Ext.require() line or not using the requires option at all, the grid loads without problems.

    Am I missing something or is there a problem in the loader?

    Regards,
    Quico

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,641
    Vote Rating
    434
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    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.

  3. #3
    Ext JS Premium Member frsantos's Avatar
    Join Date
    Dec 2011
    Posts
    3
    Vote Rating
    0
    frsantos is on a distinguished road

      0  

    Default


    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.

  4. #4
    Ext JS Premium Member frsantos's Avatar
    Join Date
    Dec 2011
    Posts
    3
    Vote Rating
    0
    frsantos is on a distinguished road

      0  

    Default


    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()});
    });

Tags for this Thread