View Full Version : Elements id with variables..

19 Nov 2011, 8:32 AM

I totally understand that the id's of all the elements (items) within a page should be unique. Therefore, if this property is not assigned, ExtJS does it internally and ensures to assign a unique value for it.
However, what's wrong with doing the following so that ExtJS doesn't allow it?

<script type="text/javascript">
var formPanel = Ext.create('Ext.form.Panel', {
id: 'panel'+toString(i), // or, id: 'panel'+i,
width: 250,
height: 100,
title: 'Panel '+i

This is a very important feature that prevents me of creating dynamic items and then accessing them through the Ext.getCmp('itemId') function.
The same is applied for the itemId property. However, the name property seems to take the value properly!
Why aren't the id, itemId, and name properties treated the same way?

Any workaround this?


19 Nov 2011, 9:58 AM
Could you explain in a little more detail exactly what the problem is? From your code the most obvious issue is that you're calling a function called toString(), which may not exist. Setting the id with a valid value should work as expected.

It should be noted that setting a component id does not necessarily correspond to an element id, they are distinct. However, I believe all of the standard ExtJS components do have a convention of using the component id as the id for their main element. You seem to imply in your question that you regard these 2 ids as interchangeable but it's important to realize they are two separate things.

Further, the use of Ext.getCmp is highly discouraged in real application code. One popular alternative is to use a component query, though other techniques do exist.