访问相邻组件/字段的最佳方式 [英] Best way to access adjacent components / fields

查看:112
本文介绍了访问相邻组件/字段的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种访问组件/字段的方式,它们与访问组件的数量相同,或者仅在同一个父项数组中(最后一个只是一个选项)。

I am looking for a way to access components / field that are either in the same items array as the accessing one or even only in a same parent items array (the last one is just a option).

在ExtJS3中,只需在所有者容器中定义一个 ref ,但我没有找到任何类似的东西在ExtJS4中。

In ExtJS3 this was easy by simply defining a ref in the owner container but I didn't found anything like that in ExtJS4.

我知道我可以使用 Ext.ComponentQuery()或快捷方式 up() / down()甚至 Ext.getCmp()他们都不是我正在寻找的,因为他们只是执行一堆代码,而 ref 是一个简单的方法来做事情。
是的,我知道使用ComponentQuery比使用硬编码引用更安全的事实。但是我只是想知道是否还有其他一些方法可以实现。

I know that I can use Ext.ComponentQuery() or the shortcuts up() / down() or even Ext.getCmp() but they are all not what I am looking for, cause they just executes a bunch of code while the ref was such an easy Way to do things. Yes, I am aware of the fact that using a ComponentQuery is much more fail safe than the use of hard coded references. But I just want to know if there are some other ways to do this.

推荐答案

这里有一些我使用的技巧: / p>

Here are some tricks I have used:

//lookup by name
formPanel.getForm().findField('state'); 

//lookup using nextSibling/prevSibling in a fieldset or fieldcontainer
myField.ownerCt.nextSibling('textfield[fieldLabel=Description]')

这里 fieldLabel 属性用于缩小字段选择,但您可以使用ANY属性。因此,如果您使用属性 ref 构建一个字段,则可以使用它来选择您的字段,如何在 ComponentQuery

Here fieldLabel property is used to narrow down field selection but you can use ANY property at all. So if you construct a field with a property ref you can then use it to select your field similar how you would use it in a ComponentQuery .

这篇关于访问相邻组件/字段的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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