Quassnoi
Quassnoi

Reputation: 425371

Dynamically loading a non-class in ExtJS 4

I have two classes in ExtJS 4 (a grid and a form) with correlated properties (column and field definitions).

I want to create a common definition file for them and dynamically load it:

# app/common/Columns.js

Ext.ns('myapp.common');
myapp.common.Columns =
        [
        {
        text: 'Name',
        dataIndex: 'name',
        },
        {
        text: 'Email',
        dataIndex: 'email',
        }
        ];


# app/view/Grid.js

Ext.define
       (
       'myapp.view.Grid',
       {
       extend: 'Ext.grid.Panel',
       columns: myapp.common.Columns
       }
       );


# app/view/Form.js

Ext.define
       (
       'myapp.view.Form',
       {
       extend: 'Ext.form.Panel',
       items: myapp.common.Columns.map
               (
               function(v)
               {
                       return  {
                               name: v.dataIndex,
                               fieldLabel: v.text,
                               };
               }
               );
       }
       );

As you can see, app.common.Columns is not a class.

I know I can convert it into a class and override the form's and the grid's constructors to use it, but I'd like to keep it simple.

Do I need to add a <script> tag for app/common/Columns.js manually or there is a way to load it dynamically?

Upvotes: 1

Views: 709

Answers (1)

sha
sha

Reputation: 17860

I don't think you can load file dynamically using ExtJs loader without having a class defined there. Their loader is very picky about exactly matching class name to file name. I just tried your sample - it doesn't seems to be working.

Upvotes: 1

Related Questions