最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论