Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS alias vs id

Tags:

extjs

extjs4

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?

like image 504
Colin Avatar asked May 02 '26 17:05

Colin


1 Answers

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.

like image 56
kevhender Avatar answered May 06 '26 08:05

kevhender



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!