-
22 Feb 2012 6:13 AM #1
Unanswered: MVC/ExtJs Basics
Unanswered: MVC/ExtJs Basics
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.
Code: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) { alert(r.get('casenum')); } });
-
22 Feb 2012 6:17 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,641
- Vote Rating
- 434
- Answers
- 3107
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.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.
-
24 Feb 2012 7:44 PM #3
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 #4
@dcoan604. I believe in 4.0.7 it does remove an item from the cache when it's destroyed. From Controller.js:
http://docs.sencha.com/ext-js/4-0/so...app-ControllerCode: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.


Reply With Quote