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

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

问题描述

我很困惑我需要将哪一个用于 up() down() 和 Ext.getCmp(ID) 之间的 grep 对象.

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

对我来说,定义 ID 对象并通过 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.

例如:

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

哪个性能更好?

推荐答案

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

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.

有几篇关于此的博客和论坛帖子,以及 J. Garcia 提供的有关此主题的视频.使用 getCmp 的建议方法仅用于调试,切换到其他方法(向上、向下、参考、itemIdComponentQuery) 用于生产就绪代码.

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天全站免登陆