Arun Bertil
Arun Bertil

Reputation: 4638

Extjs Treestore child nodes not loading

I could see the child nodes loading in the first one and strangely enough not in the second one ? Any thoughts

Fiddle here

https://fiddle.sencha.com/#view/editor&fiddle/1lss

Ext.application({
    name: 'Fiddle',

    launch: function () {
        Ext.define('ComplexTree', {
            extend: 'Ext.data.TreeStore',
            alias: 'store.complextree',
            storeId: 'ComplexTree',
            root: {
                expanded: true,
                children: [{
                    text: 'test',
                    leaf: true
                }, {
                    text: 'test2',
                    expanded: true,
                    children: [{
                        text: 'test21',
                        leaf: true
                    }, {
                        text: 'test22',
                        leaf: true
                    }]
                }, {
                    text: 'test3',
                    leaf: true
                }]
            }
        });

        Ext.create('Ext.tree.Panel', {
            title: 'Complex Tree',
            width: 200,
            height: 200,
            store: Ext.create('ComplexTree'),
            rootVisible: false,
            renderTo: Ext.getBody()
        });

        Ext.create('Ext.tree.Panel', {
            title: 'Complex Tree',
            width: 200,
            height: 200,
            store: Ext.create('ComplexTree'),
            rootVisible: false,
            renderTo: Ext.getBody()
        });
    }
});

Upvotes: 1

Views: 1153

Answers (1)

Evan Trimboli
Evan Trimboli

Reputation: 30082

Because they are sharing the data set (object references). Modify your store like so:

Ext.define('ComplexTree', {
    extend: 'Ext.data.TreeStore',
    alias: 'store.complextree',

    constructor: function (config) {
        config = config || {};
        config.root = {
            expanded: true,
            children: [{
                text: 'test',
                leaf: true
            }, {
                text: 'test2',
                expanded: true,
                children: [{
                    text: 'test21',
                    leaf: true
                }, {
                    text: 'test22',
                    leaf: true
                }]
            }, {
                text: 'test3',
                leaf: true
            }]
        };
        this.callParent([config]);
    }
});

Upvotes: 2

Related Questions