1

I am developing a large enterprise application and I need to lazy load modules (another ExtJs applications) into a main application. I am trying to load app.js of other applications with Ext.Loader:

onTabChange: function (tabPanel, newCard, oldCard) {
    Ext.Loader.loadScript({
        url: 'SecondaryApp/app.js',
        onLoad: function (obj) {
            console.log('ok');
        },
        onError: function (obj) {
            console.log('ko');
        },
        scope: this
    });

    newCard.add({ xtype: 'secondarylist' });
}

The callback it's ok but when I add the secondarylist component an exception of "Uncaught Error: [Ext.create] Unrecognized class name / alias: widget.secondarylist" is being thrown. The component is:

Ext.define('SecondaryApp.view.main.List', {
    extend: 'Ext.grid.Panel',
    xtype: 'secondarylist',

    title: 'Personnel',

    columns: [
        { text: 'Name',  dataIndex: 'name' },
        { text: 'Email', dataIndex: 'email', flex: 1 },
        { text: 'Phone', dataIndex: 'phone', flex: 1 }
    ]
});

I tried to compile and load the List.js only but I have the same problem anyway. Any suggestions?

EDIT: I solved the issue (bad url '-_-) but now have another issue. If I load the js file it works properly but if I try to load the compiled js file (with Sencha Cmd) it fails because Ext.cmd is undefined. I need to load the compiled js and not the original js file. Any ideas?

jsolivellas
  • 59
  • 1
  • 6
  • 1
    Try moving the `newCard.add({ xtype: 'secondarylist' });` line into the `onLoad` callback function. – CD.. Jan 02 '17 at 18:20
  • It's not working because it's trying to load the js file from [widget/secondarylist.js](http://localhost:54320/widget/secondarylist.js?_dc=1483427659631) when `add` function is called throwing 404 not found exception. I don't understand why it's trying to load the js file when it's loaded before with `loadScript` – jsolivellas Jan 03 '17 at 07:26
  • I believe it has to do with the namespace issue of 'secondarylist'. That component isn't registered yet within the namespace of the first app, you would have to give it the full namespace ot create. Did you try Ext.create('App2.view.secondarylist', { configs.... }); – James Peruggia Jan 05 '17 at 19:18
  • Starting with Sencha Cmd 6.5 you can split your code into multiple files. To achieve this, you have to split your code into exjts packages if it’s not already done.Here are some more details I wrote for another question: https://stackoverflow.com/questions/29763532/dynamically-load-extjs-modular-application/44477623#44477623 – Artem Stepin Jun 13 '17 at 19:30

0 Answers0