如何按组件名称查询包含字符串的一部分的组件 [英] How to query a component by component name that contain some part of string

查看:62
本文介绍了如何按组件名称查询包含字符串的一部分的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Ext.ComponentQuery.query()查询包含某个路径名称的按钮名称。

I want to use Ext.ComponentQuery.query() to query name of button that contain some path of name.

假设我有4个按钮名称被声明为'edit_btn','add_btn','add2_btn'和'edit2_btn'

然后我使用查询。
Ext.ComponentQuery.query(button [name ='* edit *']);

我应该得到''edit_btn''和''edit2_btn'按钮。

Ext.ComponentQuery.query(button [name ='* add *']);

我应该得到''add_btn''和'add2_btn'按钮。

或者我可以在中使用正则表达式Ext.ComponentQuery.query()命令?

如果可以,如何使用它?

If can, How to use it?

推荐答案

没有实现。我看了源代码,只有等效运算符被实现了。 Hovewer很容易扩展它(参见ComponentQuery.html文件中的 filterByAttribute ),但是您必须从源代码复制所有代码,因为它以单例形式实现。

It's not implemented. I looked at the source code, and there is only equality operator implemented. Hovewer it's easy to extend it (see filterByAttribute in ComponentQuery.html file), but you must copy all the code from source, because it's implemented as singleton.

另一种方法是选择稍后具有名称属性和过滤器的按钮,例如:

Another way is to select buttons which have name attribute and filter later, eg:

Ext.Array.filter(
    Ext.ComponentQuery.query('button[name]'), 
    function(c){ return /^add/.test(c.name); }
)

这篇关于如何按组件名称查询包含字符串的一部分的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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