What is the difference between xtype and alias?

白昼怎懂夜的黑 提交于 2019-12-03 19:53:56

问题


What is the difference between xtype and alias used in Sencha? They're both seem to be used as shorthand in different places.


回答1:


This is really confusing, even Sencha Touch developers team does not have a common opinion.

As far as I know, they design this merely for performance. Alias appears earlier than xtype, they create xtype config because if we don't have to parse the string to get the xtype like before, it's faster.

Anyway, things like xtype, ptype, ltype or most common, alias should be unified and clarified in next releases, said the dev team.




回答2:


When you use "alias" to declare an xtype, you have to preface it with "widget".

Example:

{
   ...
   alias: 'widget.mycomponent'
   ...
}

When you use the xtype property, you can leave the "widget." part off, because that part is assumed:

Example:

{
   ...
   xtype: 'mycomponent'
   ...
}

The reason for the two different properties is because you can declare aliases of things other than "widget", like alias: 'layout.card', which is used in the framework. However, for end-user code that reference view objects, you'll probably be using either

alias: 'widget.mycomponent'

or

xtype: 'mycomponent'


来源:https://stackoverflow.com/questions/10145460/what-is-the-difference-between-xtype-and-alias

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