ExtJS alias vs id

天涯浪子 提交于 2019-12-13 13:49:55

问题


I don't understand the usage of alias vs id vs itemId config properties in ExtJS

app/view/foo.js

Ext.define('app.view.foo', {
    ...
    alias: 'widget.foo',         // 1
    id: 'foo',                   // or 2
    ...
});

app/controller/goo.js

Ext.define('app.controller.goo', {
    ...
    views: ['foo', ...],
    init: function() {
        this.control({
               'foo': {...},     // 1
               '#foo': {...}     // or 2
               ...
        });
        ...
    },
    ...
});

With alias I can use xtype easily.. but what advantage do I gain by setting id's to my views?


回答1:


An alias is set on the class definition, using Ext.define, and is what is used for the xtype when creating instances (you seem to have the hang of this). An id should be set on a class instance, e.g. when using Ext.create. This just serves as a unique identifier for a particular instance of a component.

FWIW, id should be used sparingly. You are much better served using itemId and referencing components relatively using that, rather than globally with an id.



来源:https://stackoverflow.com/questions/18472549/extjs-alias-vs-id

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