to initComponent() or not to initComponent()

前端 未结 4 1893
温柔的废话
温柔的废话 2020-11-30 19:12

I struggle when building an app in ExtJS 4, and part of that is confusion on when to configure something in initComponent() and when not to...

For example, in Sencha

4条回答
  •  悲哀的现实
    2020-11-30 19:22

    If you do not have a deep understanding of how ExtJS class system work, you may want to follow this:

    Declare all non-primitive types in initComponent().

    Terminology

    • Primitive types - strings, booleans, integers, etc.
    • Non-Primitives - arrays & objects.

    Explanation

    If the component you extend is to be created more than once, any non-primitive configs declared as a config option (outside initComponent) will be shared between all instances.

    Because of this, many people experienced issues when an extended component (typically an extended grid) is created on more than one tab.

    This behaviour is explained in sra's answer below and in this Skirtle's Den article. You may also want to read this SO question.

提交回复
热议问题