Home >Web Front-end >JS Tutorial >Each component of extjs must set a unique ID, otherwise an error will occur_extjs

Each component of extjs must set a unique ID, otherwise an error will occur_extjs

WBOY
WBOYOriginal
2016-05-16 16:44:301012browse

Each component of extjs must set a unique ID, otherwise it will cause various errors

EXTJS basically relies on ID to identify components. If you have a textfield with ID: "keyword" in panel1, and panel2 There is a textfield with the same ID in panel2. Then, when you close panel2, because extjs finds that the ID: "keyword" component in panel2 is still in use in panel1, it will not destroy it, so it becomes an isolated object. thus causing confusion.

No matter what, you must always remember that the object ID must be unique at all times. There are two ways to do this:

1. Do not specify an ID for the object, and then use the find method of the component to find the object through other attributes, such as find("name", "role"), and the result will be an array. Of course, your attributes are unique, so you can use find("name","role")[0] to reference the component.

2. You can also specify the child component in the form of parent component ID and child component ID. This method is better, and this is what extjs does internally. The ID of the child component becomes: this.id "_role ",Note that this here refers to the parent component. When instantiating, since the ID of the parent component must be unique, even if the same component is instantiated twice, the child components of the two instances have unique IDs. This can handle the ID duplication problem very well.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn