Ext.getCmp() VS Ext.get()
Ext.getCmp()
找到一个现有的(已创建的)成分在 ExtJS 组件树中。请注意,它是灰心使用它。依靠组件查询反而。
Ext.get()
找到一个DOM元素通过 ID。例如:
<html>
<body>
<div id="target">Hello, world!</div>
</body>
</html>
Ext.get('target')
将返回div#target
DOM 元素。
我个人从不使用其中任何一个。相反,我使用 ComponentQuery 查找组件,然后检索它们的 DOM 元素,如下所述。
MyCmp.getEl() VS MyCmp.el
两者都只是检索 MyCmp 组件的顶级 DOM 元素。
当前版本的 ExtJS (4.2.1) 定义了.getEl()
函数如下:
MyCmp.getEl = function () {
return this.el;
}
意思就是MyCmp.getEl()
and MyCmp.el
are 绝对平等.
Use .el
如果您希望代码简洁明了。然而,.getEl()
如果将来 ExtJS 向组件的 DOM 元素检索过程添加额外的逻辑(例如,首先检查它是否存在),这可能会很有用。
我更喜欢.el
.
MyCmp.hide() VS MyCmp.el.hide()
MyCmp.hide()
and MyCmp.el.hide()
是两个不同的函数。当前版本的 ExtJS (4.2.1) 定义如下:
MyCmp.hide = function (animateTarget, cb, scope) {
var me = this,
continueHide;
if (me.pendingShow) {
delete me.pendingShow;
} if (!(me.rendered && !me.isVisible())) {
continueHide = (me.fireEvent('beforehide', me) !== false);
if (me.hierarchicallyHidden || continueHide) {
me.hidden = true;
me.getHierarchyState().hidden = true;
if (me.rendered) {
me.onHide.apply(me, arguments);
}
}
}
return me;
}
and
MyCmp.el.hide = function (animate){
if (typeof animate == 'string'){
this.setVisible(false, animate);
return this;
}
this.setVisible(false, this.anim(animate));
return this;
}
然而,这两个函数似乎都会产生相同的结果。他们只是添加一个style="display: none;"
到组件的 DOM 元素。
I use MyCmp.hide()
.