我搜索了示例和文档,但找不到是否可以在 ComponentQuery 查询中使用通配符。我想执行以下操作:
Ext.ComponentQuery.query('button > menu > menuitem[text="Welcome*"]');
由于按钮文本将是当前用户名,例如“Welcome Shaun”。
最佳答案
尝试
Ext.ComponentQuery.query('menuitem{text.search(\'Menu Item\')!=-1}');
根据文档,您可以使用自定义表达式。这适用于我在下面包含的代码:
var toolbar = Ext.widget('toolbar', {
items : [
{
xtype:'splitbutton',
text: 'Menu Button',
iconCls: 'add16',
menu: [{text: 'Menu Item 1'},{text: 'Menu Item 2'}],
reorderable: false
},
{
xtype: 'button',
text: 'Get matches',
handler: function(){
var match = Ext.ComponentQuery.query('menuitem{text.search( \'Menu Item\' )!=-1}');
console.log( match )
}
}
]
});
Ext.widget('panel', {
renderTo: Ext.getBody(),
tbar : toolbar,
border : true,
width : 600,
height : 400
});
关于extjs - Ext ComponentQuery 通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14507207/