2016-12-06 78 views
1

我可以看到第一个加载的子节点,奇怪的是不能在第二个加载? 任何想法Extjs Treestore子节点未加载

小提琴这里

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

有趣。你有没有试过在[Sencha论坛](https://www.sencha.com/forum/)上提问? –

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

它工作真棒,请你让我知道这个config.root和调用父母做什么? –

+1

它在config上设置root属性,然后调用父构造函数,传递配置。 –