6

How can I get my application from a view? For example consider I have an application Boo and there's a view that named Boo.view.Foo.List and I want to get Boo in the view List.

Edit:

See this code, and look at the line 20.

Ext.define('Boo.view.Foo.List', {
    extend: 'Ext.panel.Panel',
    model: 'Boo.model.FooModel',
    alias: 'widget.foolist',
    store: 'FooListStore',
    initComponent: function () {
        this.columns = [
            {
                text: "Hello world",
                dataIndex: 'Time',
                flex: 1
            },
            {
                xtype: 'actioncolumn',
                width: 50,
                items: [{
                    icon: 'cancel.png',
                    tooltip: 'Cancel',
                    handler: function (grid, rowIndex, colIndex, col, e) {
                        //Now I need to get the application here, for example with self.getApplication() or something like this.
                    }
                }]
        }];

        this.callParent(arguments);
    }
});
Afshin Mehrabani
  • 33,262
  • 29
  • 136
  • 201

1 Answers1

10

You can archieve this using the appProperty

Ext.application({
    name: 'MyApp',
    appProperty: 'Current'
});

You can now call

MyApp.Current

from anywhere cause the MyApp namespace resist within the window (global) scope.

For any Version before 4.1.3 add the following line to the Launch-Method of the Application

YourAppName[this.appProperty] = this;
sra
  • 23,820
  • 7
  • 55
  • 89
  • I don't think this is a good approach to get the application in the view. With this method, I can access to all applications in the page (consider I have more than one app in the page) but I want to get related app to the view. Is it clear enough? – Afshin Mehrabani Jan 02 '13 at 10:55
  • @AfshinMehrabani Currently you can have only one application due to the design of the EventBus (will be changed with 4.2). And this is no method it is a reference applied to the namespace of the Application. Tthis is the way to get the current instance of your application recommend by Sencha and it is also clean and fast. I can't imagine any faster or cleaner way to archive this. – sra Jan 02 '13 at 10:59
  • @AfshinMehrabani Only the controller knows the application it belongs to. Currently each controller has a property `application` which you may use for this. You may set a reference on the view at create time. Anyway I can't see the sense cause your view is bound to the application by it's namespace so the use of the appProperty would be the cleanest way to archieve this. – sra Jan 02 '13 at 11:05
  • Okay you're correct, and I changed the structure of ExtJs and designed a new EventBus (I've changed the ExtJs MVC methods). So now I have more than one app in the page. However thanks for your help, I think this solutions works for now. – Afshin Mehrabani Jan 02 '13 at 11:18