View Full Version : MVC dynamic get methods and references question

8 Feb 2012, 11:12 AM
I'm looking at the "architecting your app in ext js 4" MVC tutorial (http://www.sencha.com/learn/architecting-your-app-in-ext-js-4-part-3/) and have a pair of questions...

Declaring stores, views, models, and controllers produces dynamic get methods for referencing class definition... for example (from the article):

views: ['StationsList'] // creates getter named 'getStationsListView' -> returns reference to StationsList class

My question about this is how this works for classes that have been modularized into sub-directories. So if I have a app\view\<something>\myview.js , what does the getting end up looking like? I tried doing a requires: app.<something>.myview and then using the alias declared in myview.js as the reference, but that didn't work... I can get the views tag to accept it by using 'views: [<something>.myview]' ... but that would theoretically end up with a get<Something>.myview() ... which doesn't work because of the .

The second question along these lines is for referencing instances via the "refs" tag... It seems like this is only useful in cases where a view (or other class to be referenced) lives in a static place in the application... So for an application that loads different views into the same container depending on menu selections would have less use for this... though I may be looking at it the wrong way. The net result I'd like to achieve is being able to instantiate the different views dynamically and have an instance of the appropriate controller tied to the generated view instance. On this front it seems like the non-MVC examples on the samples page come closer to replicating this than the MVC examples do, but that seems counter-intuitive. I can't shake the feeling that I'm missing something.

8 Feb 2012, 12:35 PM
It will prefix the classes in the views with your app name and view. So say your app name is MyApp, the StationsList view would be loaded with MyApp.view.StationsList. If you have views : ['list.Stations'] then it would try loading the MyApp.view.list.Stations.

8 Feb 2012, 12:50 PM
I assume that a getter is still automatically generated for defines that have a path... so using ['list.Stations'] as an example, by convention the get method would be getList.Stations ... but the . having special meaning should prevent that from being the case...

8 Feb 2012, 3:40 PM
With views: ['list.Station'], the generated getter will be getListStation(), not getList.Station(). The same for models, stores, etc

8 Feb 2012, 3:47 PM
That worked, thanks!