开发者

Instanciate a class with a given id in ExtJS

I would like to know if it is possible to instanciate a class by its id .

For example we have a class extending Ext.grid.GridPanel with an id property, is it开发者_开发技巧 possible to instanciate the class just knowing his id (which is the component id in this case) ?


Not without recursively looping over every object hanging off window, looking for id properties and then finding one that matched.


What do you mean by instantiate? If its got an id it has already been instantiated.

An id is a property on the object, not the class. Ids are not static, but belong to instances of the class once you've instantiated them. In the constructor you would set the id, which can be used later on to get an instance of the object:

Ext.getCmp('id');

will give you a reference to the ExtJS component if that is what you're after.

If you already know that its an Ext.grid.GridPanel you can instantiate a new one:

var grid1 = new Ext.grid.GridPanel({
    id: 'grid1'
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜