views:

21

answers:

1

Summary:

I want to know if it is possible to do something like this:

{a: 'A',b: this.a}

...by using some other pointer like {a: 'A',b: self.a} or {a: 'A',b: own.a} or anything else...

Full question:

I'm trying to extend MyBaseModule using Ext.extend, and need to cross-reference values in the extension object passed to Ext.extend().

Since I'm not yet in context of MyModule, I'm not able to use this to reference the object (See example below line 12). Is there any other way to reference values like this without creating the object first?

1 MyModule = Ext.extend(MyBaseModule, {
2   dataStores: {
3       myDataStore: new Ext.data.Store({...})
4   },
5
6   myGridDefinition: {
7       id:                 'myGridDefinitionPanel',
8       bodyBorder:         false,
9       items: [{
10          xtype:          'grid',
11          id:             'myGridDefinitionGrid',
12          store:          this.dataStores.myDataStore
13      }]
14  }
15 });

Or is the following the only solution? I would like to avoid this if possible, as I find it less readable for large extension definitions.

1 var extensionObject = {
2   dataStores: {
3       myDataStore: new Ext.data.Store({...})
4   },
5
6   myGridDefinition: {
7       id:                 'myGridDefinitionPanel',
8       bodyBorder:         false,
9       items: [{
10          xtype:          'grid',
11          id:             'myGridDefinitionGrid'
12      }]
13  }
14 };
15
16 extensionObject.locationsGrid.items[0].store = extensionObject.dataStores.locations;
17
18 MyModule = Ext.extend(MyBaseModule, extensionObject);
+1  A: 

You could just build the object progressively:

var dataStores = {
    myDataStore: new Ext.data.Store({...})
};

var extensionObject = {
    dataStores: dataStores,
    myGridDefinition: {
        id: 'myGridDefinitionPanel',
        bodyBorder: false,
        items: [{
            xtype: 'grid',
            id: 'myGridDefinitionGrid',
            store: dataStores.myDataStore
        }]
    }
};

Another approach:

var extensionObject = {
    dataStores: {
        myDataStore: new Ext.data.Store({...})
    }
};

extensionObject.myGridDefinition = {
    id: 'myGridDefinitionPanel',
    bodyBorder: false,
    items: [{
        xtype: 'grid',
        id: 'myGridDefinitionGrid',
        store: extensionObject.dataStores.myDataStore
    }]
};
owlness
I guess there is no other way. I was hoping to avoid fragmenting the object definition like this, but I'm probably just beeing difficult...
Ivar Bonsaksen