Aakash Sahai
Aakash Sahai

Reputation: 4004

Ext Component Query Selector formats & options

I am a novice in Sencha Touch 2 & Ext too. I have jquery knowledge, so I am relating few things similar for quick understanding but got stuck in selector query.

I am creating dynamic textfields like:

var autoSuggestField = 'people_' + counter;  // suppose counter is looping 5 times
var field =  new Ext.field.Text({
        name: autoSuggestField,
        itemId: 'testing',                   // just for testing
        // itemId: autoSuggestField,         // actual code
        inputCls:'auto-suggest',
        placeHolder:'Select People',
        cls:'place-holder',
        listeners: {
            clearicontap:function(obj, e, eOpts) {
                // tried option 1
                var allPeople = Ext.ComponentQuery.query('.place-holder .auto-suggest');
                console.log(allPeople);           // console says '[]'

                // tried option 2
                var allPeople = Ext.ComponentQuery.query('.place-holder');
                console.log(allPeople);           // console says '[]'

                // tried option 3
                var allPeople = Ext.ComponentQuery.query('.auto-suggest');
                console.log(allPeople);           // console says '[]'

                // tried option 4
                var allPeople = Ext.ComponentQuery.query('#testing');
                console.log(allPeople);           // console says '[class , class, class]'
            }
        }
    });

But I am looking for something:

// var allPeople = Ext.ComponentQuery.query('[name^=people_]');    // as we do jquery   

Or anything similar to it, which should work. Please clear what I am doing wrong in option[1,2,3] as most of the post says that using id[option 4] is bad. An how can we achieve using [name^=] "which says any element starting with people_". Is it possible in Ext? Is it possible through REGEX?(just for an idea)

Please add explanations for better understanding of selectors.

Upvotes: 0

Views: 684

Answers (1)

Sreek521
Sreek521

Reputation: 669

Instead of looking for regular expressinons you can add a an extra config like type:'people' for all the people related textfiled components and you can query it using the

 var allPeopleComponents = Ext.ComponentQuery.query('textfield[type=people]');

The above will return the array of components having type='people'.

Please take a look here and for better understanding of ComponentQuery options here

Hope it helps you.

Upvotes: 1

Related Questions