up()和down()与Ext.getCmp() [英] up() and down() versus Ext.getCmp()

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

问题描述

我很困惑我需要在up()down()和Ext.getCmp(ID)之间使用grep对象。



对我来说,通过Ext.getCmp('ID')
定义ID以对象和检索对象更容易,代码看起来更干净。



例如:

  console.log(this.up('panel')。up('panel')。down('grid') ); 
console.log(Ext.getCmp('myPanel'));

哪一个更适合演出?

解决方案

使用ID和getCmp找到您的组件存在严重问题。主要的问题是您不能安全地重用该组件,因为在大多数情况下,标记将创建具有重复ID的HTML元素,这是无效的HTML。另外,当您有两个具有相同ID的组件时,您将遇到难以追踪的意外行为,因为框架将无法正确引用您的组件。



有几个博客和论坛帖子,以及J. Garcia的视频涵盖这个话题。使用getCmp的建议方法仅用于调试,切换到其他方法(上,下,refs, itemId ComponentQuery )用于生产就绪代码。


I'm very confused which one I need to use for grep object between up() down() and Ext.getCmp(ID).

For me, it is easier that define ID to object and retrieve the object by Ext.getCmp('ID') and the code looks more clean.

For example:

console.log(this.up('panel').up('panel').down('grid'));
console.log(Ext.getCmp('myPanel'));

which one is better for performance?

解决方案

There are severe gotchas with using IDs and getCmp to find your components. The primary issue is that you can not reuse the component safely because in most cases the markup will create HTML elements with duplicate IDs, which is invalid HTML. Additionally, when you have two components with the same ID you will run into unexpected behavior that is difficult to track because the framework will not get a correct reference to your components.

There are several blog and forum posts on this, as well as a video by J. Garcia covering this topic. The suggested way to use getCmp is for debugging only, switching to other methods (up, down, refs, itemId, and ComponentQuery) for production-ready code.

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

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