Results 1 to 7 of 7

Thread: records [i] is undefined in AbstractView.updateIndexes when expanding 2nd tree node

  1. #1
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    43
    Answers
    2

    Default Answered: records [i] is undefined in AbstractView.updateIndexes when expanding 2nd tree node

    I have a treepanel, and as the user clicks on the plus signs it fetches the next level of the tree from the server. All was working well.

    But now I've run into a problem where I'm getting an exception in ext-debug-all.js, in this code:

    Code:
        updateIndexes : function(startIndex, endIndex) {
            var ns = this.all.elements,
                records = this.store.getRange(),
                i;
    
    
            startIndex = startIndex || 0;
            endIndex = endIndex || ((endIndex === 0) ? 0 : (ns.length - 1));
            for (i = startIndex; i <= endIndex; i++) {
                ns[i].viewIndex = i;
                ns[i].viewRecordId = records[i].internalId;
                if (!ns[i].boundView) {
                    ns[i].boundView = this.id;
                }
            }
        },
    The bolded line is where the problem is occurring.

    I see that I'm not the only one to hit a problem here:

    http://www.sencha.com/forum/showthre....updateIndexes
    http://www.sencha.com/forum/showthread.php?191149

    Is there still a bug in this area? I'm using ExtJS 4.1.3.

    What I'm seeing in the debugger is that sure enough, the ns array has one more item than the records array, hence the exception.

    What I'm noticing is that this happens when I expand a second node that has the same name as another node that's already been expanded. The same name, but not the same id. I'm assuming the same name or text shouldn't matter, correct?

    So for example if my tree looks like:

    product1
    product2
    ----groups
    ----installation-images
    ----nodes
    ----revision-images
    ----template-images
    product3
    ----groups
    ----installation-images
    ----nodes
    ----plugin-images
    product4
    product5

    If I expand 'nodes' under product2, then expand 'nodes' under product3, I hit this exception. I also hit it if I expand those nodes called 'nodes' in the opposite order. When I expand all the items in each array in the debugger, I see there's a duplicate product5 in the ns array. That sure smells like an ExtJS bug (as in, something isn't getting cleaned up).

    (As another point of reference, if I create a couple of groups under product2/groups, and then expand each node (Group1, then Group2), I'll hit the same exception.)

    I'm honestly not sure if I'm doing something wrong, or if there's another bug in ExtJS.

    But if someone could point me in a direction so I could debug this, I'd be really grateful. For example, what's this ns array, and who populates it? If I could figure that out, then I could probably figure out where the duplicate entry is coming from.

    Thanks,


    Brian

  2. All this id's have to be unique

  3. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,256
    Answers
    759

    Default

    See: http://www.sencha.com/forum/showthre...l=1#post918344

    It's typically caused by duplicate ids.
    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.

  4. #3
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    43
    Answers
    2

    Default

    I was just realizing that myself. I found if I expand both nodes called 'groups', no problem occurs, because there are 2 groups defined under product2 but none under product1.

    But nodes *happens* to have the same exact data under both 'nodes'.

    I've found the following id's:

    node.data.id
    node.id
    node.internalId

    Can you explain what each id is used for? Which one or ones should be unique? Are there any (like maybe internalId) that shouldn't be touched by user code? Are there other id's I'm not aware of?

    Thank you,


    Brian

  5. #4
    Sencha User Jad's Avatar
    Join Date
    Feb 2012
    Location
    annecy france / geneve suisse
    Posts
    149
    Answers
    12

    Default

    All nodes have to be uniques

    if you duplicate some nodes like this
    node1 = nodeModel
    try this
    node1 = nodeModel.copy()

  6. #5
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    43
    Answers
    2

    Default

    Thanks, but I'm not explicitly duplicating anything. If there's duplication going on, it's coming from the server.

    But back to my question, which of the id's that I mentioned needs to be unique? Or is it all of them?

    For reference, here are the ID's I've discovered:

    <node>.id
    <node>.internalId
    <node>.data.id

    Are there any others? And I'm assuming the text can be duplicated without issue, yes?

    I could use a scheme where the parent's id becomes part of the child's id, which will guarantee uniqueness, but without knowing how these different id's are used, I'm not sure which one(s) I should be making unique and which I should be leaving alone.

    Thanks,

    Brian

  7. #6
    Sencha User Jad's Avatar
    Join Date
    Feb 2012
    Location
    annecy france / geneve suisse
    Posts
    149
    Answers
    12

    Default

    All this id's have to be unique

  8. #7
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    43
    Answers
    2

    Default

    Thank you.

    With so many id's, it's unnerving to mess with all of them without knowing what they're used for. I think it'd be a cleaner model to only have one id per tree node.

    I implemented my fix, and it seems to be working.

    Thanks again,


    Brian

Posting Permissions

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