dgcipp
dgcipp

Reputation: 339

EXTJS setRootNode possible bug

I got a treepanel and tree store, and I want to save my treepanel into the store, for that I am using:

var treepanel = Ext.create('Ext.tree.Panel', {
         title: 'Tree example',
         store: store,
         rootVisible: false,
         lines: true
});

var store = Ext.create('Ext.data.TreeStore', {
    root: {
        expanded: true,
    }
});

var button = Ext.create('Ext.button.Button', {
    text: 'test',
    handler: function() {
         treepanel.getRootNode().appendChild({text: 'child',
                                              leaf: true});
         store.setRootNode(treepanel.getRootNode());
    }
});

But this doesn't work, however if I create a variable like:

var aux = { root:{ 
                  expanded: true,
                  children: [{
                            text: 'child',
                            leaf: true
                           }]
           }}

And I use in the same way:

store.setRootNode(aux);

This works fine. Any idea?, here is fiddle example where you can play with buttons 1 and 2 and check with firebug the error: http://jsfiddle.net/fL5fT/28/

Upvotes: 0

Views: 510

Answers (1)

Paweł Głowacz
Paweł Głowacz

Reputation: 3046

I think you did misunderstand some action that you wrote in fiddle:

First of all this code:

treepanel.getRootNode().appendChild({text: 'child', leaf: true});

already saved item/child to that store. So you dont need to do this:

store.setRootNode(treepanel.getRootNode());

Next confusion in above line is that you are trying to set new RootNode of the store. That case will throw error in console because you are trying to set syntactically wrong RootNode.

This code will work:

var aux = { root:{ 
                  expanded: true,
                  children: [{
                            text: 'child',
                            leaf: true
                           }]
           }}

because you have create here correct new RootNode.

You need to be aware that making new RootNode discards all the previous added items to that store.

Upvotes: 1

Related Questions