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

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

问题描述

我想使用 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'' 按钮.

I should get ''edit_btn'' and ''edit2_btn'' button.

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

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

I should get ''add_btn'' and 'add2_btn' button.

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

Or I can use regex in Ext.ComponentQuery.query() command?

如果可以,如何使用?

推荐答案

未实现.我查看了源代码,并且只实现了相等运算符.但是,扩展它很容易(请参阅 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天全站免登陆