PDA

View Full Version : Proper/appropriate way to get references to objects



scheid
22 Dec 2011, 5:09 PM
Hi All,

I'm just learning Sencha, and have seen different ways to get references to objects like views. I want to ensure that I'm doing it in a proper way that isn't spawning new instances, etc.

I use the technique below to navigate to cards in a card layout, which works well from a UI perspective. Is ComponentQuery.query a good way to get object references?


var mView = Ext.ComponentQuery.query("mainview")[0];
var moreMessagesView = Ext.ComponentQuery.query("moremessages")[0];

mView.setActiveItem(moreMessagesView);


Thanks!

aoathout
22 Dec 2011, 5:36 PM
This logic is better served in a controller and then use the 'refs' config. This will let you get references to views and keep the logic of switching views out of your UI layer. Plenty of examples / posts for using 'refs' in the forums

scheid
22 Dec 2011, 6:15 PM
Thanks so much. I'll look into incorporating the obj references there instead. I have started to use refs for some things, but don't fully understand its behavior yet. Seems powerful though.

aoathout
22 Dec 2011, 6:24 PM
Take a look at the following. Should be helpful as examples of mvc and using the new features:

http://www.sencha.com/forum/showthre...le-MVC-example

(http://www.sencha.com/forum/showthread.php?162016-Simple-MVC-example)