未捕获的错误:[Ext.create] 无法识别的类名/别名:MyApp.store.LibraryFolderTreeStore

我正在迁移 ext js 4 to ext js 5.1 。我的 extjs 4.2.1 中有代码,升级到 extjs 5.1 后出现控制台错误。它在 ExtJs 4.2.1 中运行良好,不知道为什么会这样给出错误,说

未捕获的错误:[Ext.create] 无法识别的类名/别名:MyApp.store.LibraryFolderTreeStore

Ext.define('MyApp.view.library.LibraryTreeView', {
       extend : 'Ext.tree.Panel',
       alias : 'widget.librarytreeview',
       requires: [
         'MyApp.store.LibraryFolderTreeStore'
       ],
       store : Ext.create("MyApp.store.LibraryFolderTreeStore") // getting error on this line
       ....
});
stack overflow Uncaught Error: [Ext.create] Unrecognized class name / alias: MyApp.store.LibraryFolderTreeStore
原文答案

答案:

作者头像

You cannot use Ext.Create while defining class.

You have to use initComponent method in which you can assign config using Ext.Create.

Ext.define('MyApp.view.library.LibraryTreeView', {
       extend : 'Ext.tree.Panel',
       alias : 'widget.librarytreeview',
       requires: [
         'MyApp.store.LibraryFolderTreeStore'
       ],
       initComponent : function(){
       this.store = Ext.create("MyApp.store.LibraryFolderTreeStore");
       this.callParent();
       }
        // getting error on this line
       ....
});

相关问题