【问题标题】:Extjs Treestore child nodes not loadingExtjs Treestore 子节点未加载
【发布时间】:2016-12-06 07:45:38
【问题描述】:

我可以看到子节点在第一个加载,奇怪的是没有在第二个加载? 有什么想法

在这里拉小提琴

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

【问题讨论】:

  • 有趣。您是否尝试在Sencha Forum 上提问?
  • 是的,很有趣……不,我没有

标签: javascript extjs


【解决方案1】:

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

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

【讨论】:

  • 效果很好,请告诉我这个 config.root 和 call parent 是做什么的?
  • 它在配置上设置根属性,然后调用父构造函数,传递配置。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多