Search code examples
extjsextjs4extjs4.1extjs4.2

Ext ComponentQuery wildcards


I've searched the examples and docs and I couldn't find if its possible to use wildcards in the ComponentQuery query. Id like to do the following:

 Ext.ComponentQuery.query('button > menu > menuitem[text="Welcome*"]');

Since the button text will be the current user name for example "Welcome Shaun".


Solution

  • Try

    Ext.ComponentQuery.query('menuitem{text.search( \'Menu Item\' )!=-1}');

    Per the docs, you can use custom expressions. This works for the code I've included below:

    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
        });