Results 1 to 4 of 4

Thread: MVC/ExtJs Basics

  1. #1
    Touch Premium Member
    Join Date
    Nov 2011
    Posts
    6
    Vote Rating
    0
      0  

    Default 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'));
        }
    });

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Jul 2011
    Posts
    48
    Vote Rating
    1
      0  

    Default

    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?

  4. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,790
    Answers
    583
    Vote Rating
    391
      0  

    Default

    @dcoan604. I believe in 4.0.7 it does remove an item from the cache when it's destroyed. From Controller.js:

    Code:
    cached.on('beforedestroy', function() {
        me.refCache[ref] = null;
    });
    http://docs.sencha.com/ext-js/4-0/so...app-Controller

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •