如何在 ExtJs 面板中搜索子项

发布于 2025-01-02 19:52:22 字数 218 浏览 2 评论 0原文

如何使用子项的 id 查找面板中是否存在特定子项(项目)。

假设我有一个父面板 (id =parentPanel) 和几个面板作为该父面板的项目。现在,我想搜索 id 为“childPanel09”的面板是否是父面板的子面板。

[可能不使用迭代]

注意:我正在使用 ExtJs 3.4

How can I find if a particular child (item) exists in a panel using the id of the child.

Say I have a parent paned (id = parentPanel) and few panels as items of this parent panel. Now, I would like to search if a panel by id 'childPanel09' is a child of parent panel.

[Possibly without using iteration]

Note: I am using ExtJs 3.4

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷爱 2025-01-09 19:52:22

如果您只想在parentPanel的直接子级中搜索,可以使用 getComponent

var childPanel = Ext.getCmp('parentPanel').getComponent('childPanel09');
if (childPanel) {
  alert('yes. child exists');
}

如果您不仅想在直接子级中搜索,而且想在parentPanel下的任何层中搜索,您可以使用查找

var childPanel = Ext.getCmp('parentPanel').find('id', 'childPanel09')[0]; // [0] because find returns array
if (childPanel) {
  alert('yes. child exists');
}

If you want to search only among direct childs of parentPanel you can use getComponent:

var childPanel = Ext.getCmp('parentPanel').getComponent('childPanel09');
if (childPanel) {
  alert('yes. child exists');
}

If you want to search not only among direct childs but at any layer under the parentPanel you can use find:

var childPanel = Ext.getCmp('parentPanel').find('id', 'childPanel09')[0]; // [0] because find returns array
if (childPanel) {
  alert('yes. child exists');
}
长伴 2025-01-09 19:52:22

Ext.Container.find() (来自已接受的答案)很好 自 ExtJS 3.4 起(这就是问题所问的内容)。然而,在 ExtJS 4.0 及更高版本中,find() 被删除,取而代之的是 Ext.Container.query(),它完成同样的事情。

Ext.Container.find() (from the accepted answer) is fine as of ExtJS 3.4 (which is what the question asked about). However, in ExtJS 4.0 and above, find() was removed in favour of Ext.Container.query(), which accomplishes the same thing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文