-
24 Apr 2012 1:14 AM #1
How to load controllers dynamically?
How to load controllers dynamically?
The question is in the topic. I'm trying to do it in Sencha Touch 2.0 according to solution in ExtJS 4 (http://www.sencha.com/forum/showthre...oller&p=787028), but unfortunately it isn't working.
I added in my application function for loading controllers.
But the problem is that self.controllers.add(classPath, controller) can't be done, because self.controllers in Sencha Touch is an array (not class object) and it hasn't method add(). How to load instance of controller in app?Code:Ext.app.Application.prototype.addController = function(classPath, config) { var self = this, config = config || {}; Ext.Loader.setConfig({ enabled: true }); Ext.require(classPath); Ext.require(classPath, function() { var controller = Ext.create(classPath, Ext.apply({ application : self }, config.options || {})); //self.controllers.add(classPath, controller); self.controllers.push(classPath); controller.init(); if (config.callback) { config.callback.call((config.scope || this), config); } }); };
And of course, after method init() when I try to get my added before controller I get nothing. My code:
myController is undefined (but I see ContactsController in array of controllers ('cause I pushed it in array self.controllers) but it's not loaded.Code:var app = this.getApplication(); app.addController('ContactsController', { callback : function() { console.log(self.application); } }); var myController = this.getApplication().getController('ContactsController');
-
26 Apr 2012 7:29 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
It is a better idea to load everything up front on a mobile device. If the connection goes out, your app won't function correctly or even if the connection is slow your app will come to a halt.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
26 Apr 2012 8:10 AM #3
You see, our main idea is to give our customers a tool where they can change the view of their mobile pages as they want (to add new field, to hide some controls, etc.), that's why Sencha's static model/architecture is not well for us. We need to get the structure of pages/views, controllers, stores from the web server via AJAX.
-
12 May 2012 9:13 AM #4
How to remove controller?
How to remove controller?
And we almost did it. We are successfully adding new controllers, views and model from server, using AJAX. Here is the code:
But now we have a problem with removing of controllers. How to do it?Code:Ext.app.Application.prototype.addController = function(classPath, config) { var self = this, config = config || {}; Ext.Loader.setConfig({ enabled: true }); Ext.require(classPath, function() { var controllers = self.getControllerInstances(); if (!controllers[classPath]) { var controller = Ext.create(classPath, Ext.apply({ application : self }, config.options || {})); controllers[classPath] = controller; self.controllers.push(classPath); controller.init(); if (config.callback) { config.callback.call((config.scope || this), config); } } }); };
-
13 May 2012 11:53 PM #5
Has anybody idea how to do it? And is it Ok to use
self.getControllerInstances()?
-
3 Sep 2012 11:51 PM #6
Very Interesting,
I tried to add a controller with code got by ajax and it works!
Did you manage to remove a controller ?
Thanks


Reply With Quote