how to change the way showing plus before a non-leaf node into showing plus before a node containing any children in an extjs treepanel?

StackOverflow https://stackoverflow.com/questions/23547532

Question

Code: Demo

This is the modified tree data from an example of book ExtJs in Action:

     var store = Ext.create('Ext.data.TreeStore', {
        root: {
            text: 'Root Node',
            expanded: false,
            children: [{
                text: 'Child 1',
                leaf: false     //<---------Modified (from true to false)
            }, {
                text: 'Child 2',
                leaf: true
            }, {
                text: 'Child 3',
                children: [{
                    text: 'Grand Child 1',
                    children: [{
                        text: 'Grand... you get the point',
                        leaf: true
                    }]
                }]
            }]
        }
    });

When expanding Root Node, you would find a + before Child 1 for this node is not a leaf. However, there is nothing in Child 1.

Question:
Is there some method to change the way of showing + before a node through judging whether there is any children node in it? Thanks for any help.

Était-ce utile?

La solution

If parent has no children, then set loaded attribute as true in JSON responce or root(in your case).

your root config should look like this

root: {
        text: 'Root Node',
        expanded: false,
        children: [{
            text: 'Child 1',
            leaf: false,
            loaded:true
        }, {
            text: 'Child 2',
            leaf: true
        }, {
            text: 'Child 3',
            children: [{
                text: 'Grand Child 1',
                children: [{
                    text: 'Grand... you get the point',
                    leaf: true
                }]
            }]
        }]
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top