到 initComponent() 或不到 initComponent() [英] to initComponent() or not to initComponent()

查看:21
本文介绍了到 initComponent() 或不到 initComponent()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ExtJS 4 中构建应用程序时我很挣扎,其中一部分是关于何时在 initComponent() 中配置某些内容以及何时不...

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...

例如,在 Sencha 自己的 MVC Application Architecture 文档中,当首先创建网格视图,他们在 initComponent() 方法中定义了内联存储.(参见定义视图"部分)

For example, in Sencha's own MVC Application Architecture doc, when first creating the grid view, they defined the inline store in the initComponent() method. (See "Defining a View" section)

更进一步,当他们将 store 分解为一个单独的类时,他们将定义移到了 initComponent() 之外.有一个有用的评论提请注意这一事实,但没有解释.(请参阅创建模型和商店部分)

Further down, when they factored out the store into a separate class, they moved the definition outside of initComponent(). There is a helpful comment that draws attention to this fact, but there is no explanation. (See Creating a Model and Store section)

我想原因应该很明显,但我想念它.有什么指点吗?

I guess the reason is supposed to be obvious, but I'm missing it. Any pointers?

推荐答案

如果您对 ExtJS 类系统的工作原理没有深入了解,您可能需要遵循以下步骤:

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

initComponent() 中声明所有非原始类型.

Declare all non-primitive types in initComponent().

术语

  • 原始类型 - 字符串、布尔值、整数等
  • 非基元 - 数组和对象.
  • Terminology

    • Primitive types - strings, booleans, integers, etc.
    • Non-Primitives - arrays & objects.
    • 如果您扩展的组件将被创建多次,任何声明为配置选项的非原始配置(在 initComponent 之外)将在所有实例之间共享.

      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.

      此行为在下面 sra 的回答和 这篇 Skirtles Den 文章.您可能还想阅读这个问题.

      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.

      这篇关于到 initComponent() 或不到 initComponent()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆