javascript - ExtJs - how to set id of component when using multiple instances - Stack Overflow

I use ExtJs 4.1 and DeftJs.When using multiple instances of the same views at the same time, there is a

I use ExtJs 4.1 and DeftJs.

When using multiple instances of the same views at the same time, there is a problem addressing a ponent given the id: 'abc' since all instances will have the same id.

So how do I name the ids to prevent this?

One option is to create the ponents dynamically.

Another option that I would prefer is calling an ponent by id only of a certain view, like:

this.getView.getComponent('x').getId('abc')

I use ExtJs 4.1 and DeftJs.

When using multiple instances of the same views at the same time, there is a problem addressing a ponent given the id: 'abc' since all instances will have the same id.

So how do I name the ids to prevent this?

One option is to create the ponents dynamically.

Another option that I would prefer is calling an ponent by id only of a certain view, like:

this.getView.getComponent('x').getId('abc')

Share Improve this question edited Jun 12, 2012 at 13:10 tereško 58.5k25 gold badges100 silver badges150 bronze badges asked Jun 6, 2012 at 8:40 ShlomoShlomo 3,9908 gold badges52 silver badges82 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

If you can set the parent element to a unique id, you can use the itemId property on child items. Example of this from sencha's documentation (taken from the link below it):

var c = new Ext.panel.Panel({ //
height: 300,
renderTo: document.body,
layout: 'auto',
items: [
    {
        itemId: 'p1',
        title: 'Panel 1',
        height: 150
    },
    {
        itemId: 'p2',
        title: 'Panel 2',
        height: 150
    }
]
})
p1 = c.getComponent('p1'); // not the same as Ext.getCmp()
p2 = p1.ownerCt.getComponent('p2'); // reference via a sibling

http://docs.sencha./ext-js/4-0/#!/api/Ext.AbstractComponent-cfg-itemId

I try to avoid global ids and use this.getView().getComponent() from a controller to access my view. If necessary I additionally use a unique string in my id name.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745507096a4630600.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信