View Full Version : MVC/ExtJs Basics

22 Feb 2012, 6:13 AM
I am hoping to get a hand with some simple concepts of extjs 4 and your mvc best practices.

What is the best way to get references to components from within a controller that has the view referenced and outside a controller say from another view.

Ext.define('myApp.controller.orders', {
extend: 'Ext.app.Controller',
stores: [ 'orderStore' ],
models: ['order'],
views: ['orders.list', 'orders.details'],
init: function() {
this.control( {
'orderlist' : {
itemdblclick: function() {
// What is the best practices way to get a reference to the existing orderdetails
// inside the controller AND outside the controller.
'orderdetails'.expand(); //This obviously doesn't work...
console.log('Initialized Orders');

showDetails: function(g, r) {

22 Feb 2012, 6:17 AM
Each event fires with the component being fired on as the first argument usually. You can take that and use ComponentQuery to walk up and down your application structure to get the view you need. Each Component has convenient methods to do this, up, down, child, and query. They all do something different but will allow you to go up and down. This is my preferred way.

Other than that you can use refs which is a reference to a single component. Issue with this is if that component is destroyed, the ref is useless now.

24 Feb 2012, 7:44 PM
Is there any plans to improve refs system to deal with destroyed components?

I was thinking about it...

If you define the component query for example A>B>C could the controller "listen" for any component being created which matched C, and then somehow work backwards to see if component also was in B and then A. If so, then the newly matched component would get added to an array of items that the controller knew about.

If a new component was a match, the controller could also maybe see if any of it's existing array of reffed components matching this ref had been destroyed, and they could be removed and replaced with the new item.

As I see it, I can't think of any reason why you would ever want to reference a destroyed component. If a component is destroyed IMO the controller should start listening for the creation of new components matching the ref query. Until it finds one (or more) non-destroyed components it should return null.

Its seems that the controller works that way initially. Ie, the controller will return null if there is no matching components... But once ONE match is found, it locks on and caches it. Why can't it do this again when components are destroyed and new ones created?

25 Feb 2012, 4:40 AM
@dcoan604. I believe in 4.0.7 it does remove an item from the cache when it's destroyed. From Controller.js:

cached.on('beforedestroy', function() {
me.refCache[ref] = null;


However, this still doesn't handle the case where a component is moved, in which case it will no longer match the CQ but will still be in the cache.