1. #1
    Touch Premium Member
    Join Date
    Nov 2011
    Posts
    6
    Vote Rating
    0
    ldadams is on a distinguished road

      0  

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

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    898
    Answers
    3575
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jul 2011
    Posts
    48
    Vote Rating
    1
    dcoan604 is on a distinguished road

      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,625
    Vote Rating
    331
    Answers
    550
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      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.

Thread Participants: 3

Tags for this Thread