关于ext.define()中的initComponent()的最佳实践 [英] Best Practices concerning initComponent() in Ext.define()
问题描述
Ext.define()
来编写ExtJS新的MVC中的所有组件。 我无法在 initComponent()
内定义属性,或者简单地将它们设置为属性:42,
。 / p>
有广泛接受的最佳做法?
我在使用 initComponent( )
只有在必要时(即当我想要一些动态或设置一个范围),这会使功能更短,并使我有些丑陋的这个。并且始终使用它有益处,因为我不必将以前的属性移动到
initComponent()
,因为我想让它更具动态。
不幸的是,Sencha的文档对此并不太了解,可用的示例似乎按照他们想要的做法。
个人做法,当
- var时,我将声明属性区域中的变量可以定义大小,例如
x
,y
,width
height
- 正在等待被覆盖或可自定义的变量,例如
title
,saveBtnTxt
,url
,fields
,iconCls
- 这些具有特殊前缀的常量将不会被轻易地覆盖
然后我将声明项目
,监听器
, .on
, Ext.apply(me,{..})
或任何需要obj(这个
,我
),坐在我的 initComponent
里面。或者在一切设置之前应该修改/覆盖的东西,所以用户不会通过覆盖一些重要的变量来破坏我的组件。
当然这将作为我的指导2美分
编辑
关于丑陋的
,我在我的应用程序中广泛使用了变量 me
,它比这个
。这样可以帮助我更少地改变范围。
I'm writing all my components in ExtJS's new MVC fashion using Ext.define()
.
I struggle a bit whether define properties inside of initComponent()
or by simply setting them like property: 42,
.
Are there widely accepted best practices?
I'm staggering between using initComponent()
only when necessary (ie. when I want something dynamic or set a scope) which keeps the function shorter and spares me some ugly this.
s and using it always which has the benefit, that I'd never have to move former properties to initComponent()
just because I want to make it more dynamic.
Unfortunately, Sencha's docs don't tell much about that and the available examples seem to do as they want.
Personal practice, I will declare variables in the properties area when the
- variables defining magnitude, like
x
,y
,width
,height
- variables that awaiting to be overridden, or customizable, like
title
,saveBtnTxt
,url
,fields
,iconCls
- some constants, that will have special prefixes so will not be overridden so easily
Then I will declare items
, listeners
, this.on
, Ext.apply(me, {..})
or anything that requires the scope of the obj (this
, me
), to sit inside my initComponent
. Or stuff that should be modified/overridden before everything is setting up so user will not break my component by overriding some of the important variables.
Of course that'll serve as my guidance. 2 cents
EDIT
About the ugly this
, I have used the variable me
widely in my app, and it looks a lot cleaner than this
. It benefits me from changing scopes less frequently too.
这篇关于关于ext.define()中的initComponent()的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!