Uncaught Error: [Ext.createByAlias] Cannot create an instance of unrecognized alias: widget

时光毁灭记忆、已成空白 提交于 2020-01-14 07:30:10

问题


Here is a simple view that i want to instantiate :

Ext.define('myapp.view.Home',{
    extend 'Ext.Panel',
    xtype : 'testpanel' ,
    config: {
        title:'home',
        iconCls:'home',
        cls : 'home',
        html: [
           '<h1> Hello Guys </h1>',
           '<p> some text goes here </p>'
        ].join("")
    }
});

i have added the view to my controller as follows :

Ext.define('myapp.controller.Main', {
    extend : 'Ext.app.Controller',
    views : ['Home'],
    ...
}

i have used the xtype in my application as follows:

items:[{
    xtype : 'testpanel'
},

Still I get this error :

Uncaught Error: [Ext.createByAlias] Cannot create an instance of unrecognized alias: widget.testpanel

I appreciate your help.


回答1:


I think you forgot to add this view in app.js - Ext.Application's "views" array. Do check.




回答2:


Could it be fix by adding this ?

requires:[
  'myapp.view.Home'
]



回答3:


You need to use the alias property, with the widget prefix.

Ext.define('myapp.view.Home',{
    extend 'Ext.Panel',
    alias : 'widget.testpanel' ,
    config: {
        title:'home',
        iconCls:'home',
        cls : 'home',
        html: [
            '<h1> Hello Guys </h1>',
            '<p> some text goes here </p>'
        ].join("")
    }
});



回答4:


i think u need to check if files are into the right directory.

http://docs.sencha.com/ext-js/4-1/#!/guide/application_architecture

Here u could find refs to understand what could be wrong.

Check if object myapp.view.Home is in the directory app/view/Home.js

alias must be like alias : 'widget.testpanel'

and a requires:['myapp.view.Home'],

could you even post the app.js file?




回答5:


I got this exception when the xtype config/property value (of the component/object instance being created) didn't match the actual name of the xtype config of the class xtype config/property value. Where the instance is the lazy implementation of a component inside its parent component's items config.




回答6:


You can fix by adding the controller class in the view.

controller: 'ControllerClass',



来源:https://stackoverflow.com/questions/10762338/uncaught-error-ext-createbyalias-cannot-create-an-instance-of-unrecognized-al

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!