Extjs Treestore子节点未加载

时间:2016-12-06 07:45:39

标签: javascript extjs

我可以看到子节点在第一个中加载而奇怪的是不在第二个中加载? 任何想法

小提琴

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()
        });
    }
});

1 个答案:

答案 0 :(得分:2)

因为他们正在共享数据集(对象引用)。像这样修改您的商店:

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]);
    }
});