可以请详细解释一下.el,getEl(),Ext.get()吗? [英] Can you please explain .el, getEl(), Ext.get() in detail?

查看:330
本文介绍了可以请详细解释一下.el,getEl(),Ext.get()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不熟悉Sencha ExtJs



我不明白这行 Ext.getCmp('component_id')。getEl()。hide (); 。什么是 .getEl()的使用。我可以直接写 Ext.getCmp('component_id')。hide();



.el, Ext.get()还。

解决方案

Ext。 getCmp()VS Ext.get()



Ext.getCmp() >组件。请注意,不鼓励使用。依靠 ComponentQuery



Ext.get()通过ID查找 DOM元素。例如:

 < 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() code>和 MyCmp.el 绝对相等



使用 .el 如果你喜欢保持你的代码很短,甜蜜。但是,如果将来ExtJS会在组件的DOM元素检索过程中添加额外的逻辑(例如,先检查它是否存在),那么 .getEl()可能会很有用。



我更喜欢 .el






MyCmp.hide()VS MyCmp.el.hide()



MyCmp.hide() 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);
}
}
}
返回我;
}

  MyCmp.el.hide = function(animate){
if(typeof animate =='string'){
this.setVisible(false,animate);
返回这个;
}
this.setVisible(false,this.anim(animate));
返回这个;
}

但是,这两个函数似乎都产生了相同的结果 。他们只需向组件的DOM元素添加一个 style =display:none;



我使用 MyCmp.hide()


I am new to Sencha ExtJs

I did not understand the line Ext.getCmp('component_id').getEl().hide();. what is the use of .getEl(). Can i write Ext.getCmp('component_id').hide(); directly?

And explain me about .el, Ext.get() also.

解决方案

Ext.getCmp() VS Ext.get()

Ext.getCmp() finds an existing (created) component in ExtJS component tree. Note that it is discouraged to use it. Rely on ComponentQuery instead.

Ext.get() finds a DOM element by id. For example:

<html>
    <body>
        <div id="target">Hello, world!</div>
    </body>
</html>

Ext.get('target') will return div#target DOM element.

I personally never use either one. Instead, I locate components using ComponentQuery and then retrieve their DOM elements, as described below.


MyCmp.getEl() VS MyCmp.el

Both just retrieve the top level DOM element of the MyCmp component.

Current version of ExtJS (4.2.1) defines the .getEl() function as follows:

MyCmp.getEl = function () {
    return this.el;
}

Which means that MyCmp.getEl() and MyCmp.el are absolutely equal.

Use .el if you prefer to keep your code short and sweet. However, .getEl() might be useful in case if in the future ExtJS adds additional logic to the component's DOM element retrieval process (e.g. checking whether it exists or not first).

I prefer .el.


MyCmp.hide() VS MyCmp.el.hide()

MyCmp.hide() and MyCmp.el.hide() are two different functions. Current version of ExtJS (4.2.1) defines them as follows:

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;
}

However, both functions seem to produce identical results. They just add a style="display: none;" to the component's DOM element.

I use MyCmp.hide().

这篇关于可以请详细解释一下.el,getEl(),Ext.get()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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