Results 1 to 2 of 2

Thread: ItemId Increments on Consecutive Adds

  1. #1
    Sencha MVP Team Member
    Join Date
    Sep 2016
    Kennewick, WA

    Default ItemId Increments on Consecutive Adds

    I've a mobile app I'm working on using Ext JS 6.6, Modern and the Material theme.

    Now as coding adds/removes xtypes based on user actions, I'm finding the itemId when using getItemId() is returning ext-LoginMain-1, ext-LoginMain-2, ext-LoginMain-3, (Yes, these are Ext JS generated itemId's) etc., incremented by 1 for each time the item is added.

    Screen Shot 2019-02-14 at 1.53.56 PM.jpg

    Here is the code that removes the item and adds the next.

    cancelCreateAcctConfirmed: function () {
            let mainPnl = Ext.ComponentQuery.query('#MainAppPnl')[0];
            let mainPnlItems = Ext.ComponentQuery.query('#MainAppPnl')[0].getItems();
            let removePnl = mainPnlItems.getAt(0);
            removePnl.destroy(); // Destroy item to cleanup and make sure multiple classes of this panel are not added on consective adds
                xtype: 'LoginMain'
    As can be seen, I'm cleaning it up so it doesn't leak by creating more with each add by destroying the panel being removed. It can then be added again from LoginMain, this is what causes the incrementation.

    This screenshot shows I am getting the expected results other than the incrementing itemId situation.

    Screen Shot 2019-02-14 at 2.06.46 PM.jpg

    So what is causing the incrementing of the itemId and how can we control this?
    And why does in an automatically generated itemId is there an incrementation?

    It is clearly storing an array of generated itemId's, getting a count and then incrementing by one. Doing this when reading using .getItemId() then causes me to question about potential memory leaks, having multiple instances of the same component. I did validate how the code is handing it there are not multiple instances of the component, but the incrementing caused me to truly validate this the case and not a potential memory leak.

    The real resolution was to stop the auto-generated itemId by assigning the component an itemId. Even knowing this I am interested in hearing why the incrementation is happening and if there is a way to prevent it or being able to clean it up.
    Andy Allord
    Sencha MVP/Software Engineer

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Sydney, Australia


    The rules are as follows:

    1) All components are given an auto generated id, if an explicit id is not specified.
    2) The generated id comes in the form "xtype-{n}", where n is a global counter
    3) Unless you explicitly specify an itemId, the id is used as the itemId (since it's guaranteed to be unique).

    I'm not really sure why you're expecting the id to not increment as new instances are created.

    All that aside, you should be using references, the component query stuff looks like a code smell to me.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

Similar Threads

  1. Replies: 2
    Last Post: 20 Jul 2016, 7:49 PM
  2. Set tick increments on axis
    By jregan in forum Sencha Touch 2.x: Q&A
    Replies: 1
    Last Post: 26 Jun 2013, 8:32 AM
  3. [FIXED] Slider weirdness with increments
    By dcohn in forum Ext:Bugs
    Replies: 3
    Last Post: 22 Mar 2013, 6:01 AM
  4. Spinner self-increments
    By klb in forum Sencha Touch 1.x: Bugs
    Replies: 0
    Last Post: 24 Jun 2011, 5:33 AM

Posting Permissions

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