Results 1 to 9 of 9

Thread: [4.0.7] Problem with expanding node in TreePanel

  1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    19
    Vote Rating
    0
      0  

    Default Answered: [4.0.7] Problem with expanding node in TreePanel

    Ext.define('Dict', {
    extend: 'Ext.data.Model',
    fields: [
    {name:"id"},
    {name:"text"},
    {name:"leaf"},
    {name:"expandable"},
    {name:"expanded"}
    ],
    associations: [
    {type: 'hasMany', model: 'Dict', name: 'children'}
    ]
    });

    var countriesTreeStore = Ext.create('Ext.data.TreeStore', {
    model: 'Dict',
    proxy: {
    type: 'ajax',
    url: _root_url,
    reader: {
    type: 'json',
    root: 'data'
    },
    },
    root: {expanded: true, text: "Countries", leaf: false, id:"root"},
    autoLoad : false
    });

    JSON:
    {}&&{"data":[{"children":null,"expandable":true,"expanded":false,"id":4,"leaf":false,"text":"EU"},{"children":[{"expandable":true,"expanded":false,"id":5,"leaf":false,"text":"AAA"},{"expandable":true,"expanded":false,"id":6,"leaf":false,"text":"BBB"}],"expandable":true,"expanded":false,"id":41,"leaf":false,"text":"Argentina"}],"errors":null,"msg":null,"success":true,"targetUrl":null,"total":2}


    var treePanel = Ext.create('Ext.tree.Panel', {
    title: 'Countries',
    width: 300,
    height: 600,
    scroll: 'both',
    useArrows: true,
    singleExpand: true,
    renderTo : 'browseTree',
    rootVisible: false,
    store: countriesTreeStore
    });

    When I try to expand 'Argentina' node, I get the following error:
    • Uncaught TypeError: Cannot read property 'internalId' of undefined
      • Ext.define.updateIndexes ext-all-debug.js:60517
      • ext-all-debug.js:60470
      • fire ext-all-debug.js:10658
      • Ext.define.continueFireEvent ext-all-debug.js:13854
      • Ext.define.fireEvent ext-all-debug.js:13834
      • Ext.define.insert ext-all-debug.js:45162
      • Ext.define.onNodeExpand ext-all-debug.js:54195
    Additionally while debuging I can see that childnodes element of 'Argentina' node looks empty.

    I have no idea what I am doing wrong.
    Any help would be appreciated.

    Regards,
    Luke

  2. By what you write, I see you reload a child node. If you expand a node, you load that specific node. The node allready in the tree will stay there.

    If you expand or reload the root, all nodes in the tree will be removed.

  3. #2
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,184
    Answers
    87
    Vote Rating
    42
      0  

    Default

    plz use code tags. # button on the menu.

    Probably you have duplicate ids in your data, the tree can not handle that. Check you JSON!

  4. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    19
    Vote Rating
    0
      0  

    Default

    You are right. The problem was in JSON.
    When I changed JSON root name to 'children', it started to work well.
    I was able to expand node.

    But I decided to load every level of tree on expand, and I have experienced the same error while expanding.
    JSON - first level:
    Code:
    {"children":[{"children":null,"expandable":true,"expanded":false,"id":"4-1","leaf":false,"text":"EU"},{"children":null,"expandable":true,"expanded":false,"id":"7-1","leaf":false,"text":"Afghanistan"},{"children":null,"expandable":true,"expanded":false,"id":"33-1","leaf":false,"text":"Aland Islands"}]}
    JSON - second level:
    Code:
    {"children":[{"children":[{"expandable":true,"expanded":false,"id":"5-2","leaf":false,"text":"AAA"},{"expandable":true,"expanded":false,"id":"6-2","leaf":false,"text":"BBB"}],"expandable":true,"expanded":false,"id":"4-1","leaf":false,"text":"EU"},{"children":null,"expandable":true,"expanded":false,"id":"7-1","leaf":false,"text":"Afghanistan"},{"children":null,"expandable":true,"expanded":false,"id":"33-1","leaf":false,"text":"Aland Islands"}]}
    I think that this time it regards to problem with refresh of view after loading treeStore.
    I get index out of bounds records[i] at i=3 (image).

    1.jpg

    Any help would be appeciated.

    Regards,
    Luke

  5. #4
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,184
    Answers
    87
    Vote Rating
    42
      0  

    Default

    check if you have a double id on a node. if an id exists on another branche as well, you will get this error

    for example node 4-1 you have in the first and in the second level.

  6. #5
    Sencha User
    Join Date
    Nov 2011
    Posts
    19
    Vote Rating
    0
      0  

    Default

    No, it's not this.

    The second JSON is first JSON enriched with children for expanding node. The ids are unique within each JSON.

    Any help would be appreciated.

    Regards,
    Luke

  7. #6
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,184
    Answers
    87
    Vote Rating
    42
      0  

    Default

    It doesn't matter if the ids are unique within the JSON. It must be unique within the tree.

    If you add the first json to the tree with for example the id 4_1 and you add the second json with again a node 4_1 then you have two nodes with the same id.

    result, nodes that are not collapsing.

    You can check it, if this is right. Then there should be no problem when you add the first JSON, and after adding the second json the collapsing error occurs.

  8. #7
    Sencha User
    Join Date
    Nov 2011
    Posts
    19
    Vote Rating
    0
      0  

    Default

    I thought that after expanding node (=reloading treestore) newly returned JSON replaces automatically the old one. Thus there can't be some problem with uniqueness of ids. The returned JSON is not appended to existing treestore, isn't it?

    Should I make some manual clearing before reloading treestore?

    Regards,
    Luke

  9. #8
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,184
    Answers
    87
    Vote Rating
    42
      0  

    Default

    By what you write, I see you reload a child node. If you expand a node, you load that specific node. The node allready in the tree will stay there.

    If you expand or reload the root, all nodes in the tree will be removed.

  10. #9
    Sencha User
    Join Date
    Nov 2011
    Posts
    19
    Vote Rating
    0
      0  

    Default

    Thanks a lot. Your last reply is crucial!:-)

Posting Permissions

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