Poney
Poney

Reputation: 37

ExtJS 4.2.1 , Tree, adding children to a node

I am working with ExtJS 4.2.1

I am trying to append children to a leaf when I click on it. It initially is a leaf, the click transform it into a folder and I would like to append leaves as children to this node.

It worked in Ext 3.4 but it seems there is a problem with the appendChild() method in 4.2.1. I get an Uncaught TypeError: Object [object Object] has no method 'updateInfo' from this method due to node.updateInfo(commit); that we can find in appendChild().

This is a pretty simple instruction:

In Ext3

    node.leaf = false; 
        // add nodes in trees
        for  ( i =0 ; i < timesheetData.length ; i++ ) 
        {
            // we create a new node and state it's a timesheet 
            var newNode =  new Ext.tree.TreeNode({
                 id : timesheetData[i].id, 
                 text : timesheetData[i].text, 
                 ts : true }) ;
            node.appendChild(newNode);

        } 
    node.expand(); 

In Ext4

    node.set('leaf', false); 
        // add nodes in trees
        for  ( i =0 ; i < timesheetData.length ; i++ ) 
        {

            node.appendChild({
                 id : timesheetData[i].id, 
                 text : timesheetData[i].text, 
                 ts : true });

        } 
    node.expand();

Ext.tree.TreeNode doesn't exist anymore in 4.2.1. So I try to append the child directly. But it doesn't work!

What could I do?

Thank you

Upvotes: 1

Views: 4356

Answers (1)

Mel
Mel

Reputation: 31

Try this in your tree listener:

itemclick: function( record, item, index, e, eOpts ){
            item.appendChild({
                text: 'Hi! I am a leaf',
                leaf: true
            });
           }

Upvotes: 3

Related Questions