Uncaught TypeError: Cannot read property 'getRootNode' of undefined in ExtJs

Uncaught TypeError: Cannot read property 'getRootNode' of undefined in ExtJs

我正在尝试使用在商店中硬编码的商店数据来形成树检查树,但我无法实现这一点,并且出现以下错误

我是 extjs 的新手,有人知道这个问题吗?

Uncaught TypeError: Cannot read property 'getRootNode' of undefined

Store
Ext.define('my.store.ModuleHomeStore', {
    extend: 'Ext.data.TreeStore',
    autoLoad : false,
    root: {
        text:'test Object Tree',
        id:'TestTreeStoreId',
        expanded: true,
        children: [{
                          "text":"AntiVirus Software",
                          "id":"46",
                          "leaf":"false"
                       },
                       {
                          "text":"Appliance",
                          "id":"68",
                          "leaf":"false"
                       }
                    ]
    },    
    folderSort: true,
    sorters: [{
        property: 'text',
        direction: 'ASC'
});
}];

views
Ext.define('my.view.MainTree', {
    extend : 'Ext.tab.Panel',
    width : 400,
    height : 600,
    alias : 'widget.MainTreeTest',
    name : 'mainTree',
    plain: true,
    items : [{
                    xtype: 'pTree',         
                    width:219,
                    height:700,
                    bbar: [{
                            xtype: 'button', 
                            text: 'Cancel' 
                            },{
                                xtype: 'button', 
                                text: 'Ok' 
                            }]
            }]
});


Ext.define('my.view.PreTree', {
    extend : 'Ext.tree.Panel',
    title: 'MyPreference',
    alias : 'widget.pTree',
    id : 'preid',
    store: 'ModuleHomeStore',
    height: 600,
    width: 400,
    multiSelect: true,
    rootVisible : false,
    resizable:false,   
    hideHeaders : true,
    sortable : true,
    xtype:'check-tree'
});

我已经为你制作了小提琴。他们有您的代码的工作示例。 有几点,你知道ExtJs是基于MVC的框架,所以请按照MVC结构实现一切。

唯一与您的代码相关的问题是您认为:

store: 'ModuleHomeStore',

没有返回商店实例。一种方法是像 fiddle.

中那样使用 Ext.data.StoreManager.lookup 使用查找存储

或者您可以像这样创建一个商店实例 here

这也是另一个SO question建议的另一种解决方案。但是你应该实施适当的控制器并分离你的视图、存储、模型以完全控制框架。