[CLOSED] How to iterate through the list of components efficiently?

  1. #1

    [CLOSED] How to iterate through the list of components efficiently?

    Hi,

    Could you suggest an efficient approach to iterating through the list of client side components on the page? In v1.7, I had a utility function (its purpose was to close all Notification windows) do it for me as below:

    var hideNotifications = function () {
        Ext.ComponentMgr.all.each(function (c) {
            if (c.initialConfig && c.initialConfig.cls && c.initialConfig.cls.indexOf("x-notification") > -1) {
                c.close();
            }
        });
    };
    Now, the aforementioned code snippet doesn't work under v3.2 due to certain breaking changes. I came up with the following replacement:

    var hideNotifications = function () {
        Ext.ComponentMgr.each(function (c) {
            var cmp = Ext.getCmp(c);
            if (cmp.initialConfig && cmp.initialConfig.cls && cmp.initialConfig.cls.indexOf("x-notification") > -1) {
                cmp.close();
            }
        });
    };
    While doing the trick, it leaves me concerned about performance penalties associated with getting a handle on every component object on the page in a loop. Can it be made more robust?
    Last edited by Daniil; Aug 16, 2015 at 6:53 PM. Reason: [CLOSED]
  2. #2
    Hi Vadym,

    The first argument of a function that you pass to ComponentMgr' each method is a key, i.e. a component's id.
    http://docs.sencha.com/extjs/5.1/5.1...er-method-each

    The second argument is a component itself. So, this should be working.
    Ext.ComponentMgr.each(function (id, c) {
        if (cmp.initialConfig && cmp.initialConfig.cls && cmp.initialConfig.cls.indexOf("x-notification") > -1) {
            cmp.close();
        }
    });
  3. #3
    Thanks, Daniil, that works well for me. Please close this thread down.

Similar Threads

  1. Iterate items of tabPanel with tabs added by CodeBehind
    By fabricio.murta in forum 2.x Help
    Replies: 2
    Last Post: Oct 14, 2014, 6:19 PM
  2. Iterate ComboBox Items
    By Alaswad in forum 2.x Help
    Replies: 1
    Last Post: Sep 17, 2014, 5:27 PM
  3. [CLOSED] [RAZOR] Iterate over controls in FormPanel
    By gets_gui in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: May 09, 2012, 2:20 PM
  4. Replies: 2
    Last Post: Mar 22, 2011, 4:33 PM
  5. [CLOSED] Store iterate
    By 78fede78 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 22, 2010, 4:09 PM

Tags for this Thread

Posting Permissions