-
18 Dec 2012 7:49 AM #1
Answered: Question regarding namespace in app.js
Answered: Question regarding namespace in app.js
Hi all,
I'm new to Extjs, just migrating from Touch.
I've created my app today, but can't seem to use the namespace AppName.app.func()
Although calling AppName.app.func() works on ST2, this doesn't work on Extjs for some reason, and if I'm not missing something it should work the same way.Code:Ext.require('Ext.container.Viewport'); Ext.require('Ext.form.Panel'); Ext.application({ name: 'Admin', appFolder: 'app', launch: function () { //Check if user is signed in Ext.Ajax.request({ ... success : function(response, opts) { Here, after I performed the check I want to call: Admin.app.enterAdmin(); }, }); }, enterAdmin: function () { Ext.create('Ext.container.Viewport', { ...
BTW, if there's a better way to implement this, don't hesitate.
Thanks!
-
Best Answer Posted by slemmon
I've wondered about that before, too. From what I've sen ExtJS doesn't get namespace.app created automatically. I saw mitchell recommend doing the following in either the application's init or launch method:
either
Code:init: function () { Admin.app = this; // .... }That way from any controller or from the app itself you can use Namespace.app.method().Code:launch: function () { Admin.app = this; // .... }
Init is called before launch, so if you're going to use Namespace.app.method() in launch it'd be best to set up Namespace.app in the init method.
EDIT: I believe in earlier versions of ExtJS 4 init didn't get fired at all. I know it was fixed, but I don't know when that was. I'm using 4.1.1a and it's for sure fixed there.
-
19 Dec 2012 12:28 PM #2
Monti123,
You need to set a scope for the Ext.AJAX.request() object. See if the following code works for you.
Code:launch: function () { //Check if user is signed in Ext.Ajax.request({ ... success : function(response, opts) { Here, after I performed the check I want to call: this.enterAdmin(); }, scope: this }); },
-
19 Dec 2012 9:41 PM #3
I've wondered about that before, too. From what I've sen ExtJS doesn't get namespace.app created automatically. I saw mitchell recommend doing the following in either the application's init or launch method:
either
Code:init: function () { Admin.app = this; // .... }That way from any controller or from the app itself you can use Namespace.app.method().Code:launch: function () { Admin.app = this; // .... }
Init is called before launch, so if you're going to use Namespace.app.method() in launch it'd be best to set up Namespace.app in the init method.
EDIT: I believe in earlier versions of ExtJS 4 init didn't get fired at all. I know it was fixed, but I don't know when that was. I'm using 4.1.1a and it's for sure fixed there.
-
19 Dec 2012 11:19 PM #4
Didn't know that it's a known thing that this doesn't happen automatically.
Great solution slemmon, thanks.
-
20 Dec 2012 12:12 AM #5
After I saw mitchell do it I've used it ever since.
I'll be excited for ExtJS 7 or Touch 5 or Sencha TotallyRad v.1 or whatever comes along that makes ExtJS and Touch the same thing.


Reply With Quote