Ext.getCmp(id)或Ext.ComponentQuery.query(attribute) [英] Ext.getCmp(id) or Ext.ComponentQuery.query(attribute)

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

问题描述

我很熟悉Extjs并使用Extjs v4.2.0。要找到一个对象,我可以使用Ext.getCmp(id)或Ext.ComponentQuery.query(attribute)。哪一个更好的使用和更快?

解决方案

最好是避免直接使用这两个。 Ext.getCmp 特别被认为是代码气味。您应该努力组织您的代码,使其不需要它们。



组件查询优雅,但您应该使用父容器(从而减少研究树,并允许您利用相对 itemId ),或来自控制器。这是我的猜测,控制器是组件查询添加到Ext4的真正原因。


I am new to Extjs and using Extjs v4.2.0. To find an object I can use either Ext.getCmp(id) or Ext.ComponentQuery.query(attribute).Which one is better to use and faster?

解决方案

The best is to avoid using any of this two directly. Ext.getCmp is especially considered bad "code smell". You should strive to organize your code in such a way that you don't need them.

Component queries are elegant, but you should use them either from a parent container (thus reducing the research tree and allowing you to leverage relative itemId), or from a controller. It is my guess that controllers are the true reason why component queries have been added to Ext4.

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

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