PDA

View Full Version : ComponentQuery does not retrieve component by id using hash?



halcwb
2 May 2012, 9:03 AM
I have a component with id: productSubstanceTestGrid

If I use:


Ext.ComponentQuery.query('#productSubstanceTestGrid')

To retrieve the component, the result is empty.

However using this syntax, the component can be retrieved:


Ext.ComponentQuery.query('[id=productSubstanceTestGrid]')

This is not according to the documentation: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.ComponentQuery

(I just switched to Ext 4.1)

Tim Toady
2 May 2012, 11:51 AM
Remove the brackets. They are used to find attributes eg 'textfield[name="fred"]'

halcwb
2 May 2012, 10:46 PM
Remove the brackets. They are used to find attributes eg 'textfield[name="fred"]'

Thanks the brackets were a copy paste typo, the problem also occurs without the brackets.

Tim Toady
3 May 2012, 5:44 AM
I just tested and it works fine for me on 4.1. Could you be attempting it after the component is destroyed or before it is created? Could there be a typo in the query or id that is causing it?

börn
3 May 2012, 10:06 AM
the # syntax works very well over here... - do you tried this directly in a browsers console?

halcwb
12 May 2012, 9:42 PM
I just tested and it works fine for me on 4.1. Could you be attempting it after the component is destroyed or before it is created? Could there be a typo in the query or id that is causing it?

I just tried it again, using component query to find all windows and then using an id to pick out a specific window, same problem there.

halcwb
12 May 2012, 9:43 PM
the # syntax works very well over here... - do you tried this directly in a browsers console?

Yes, the examples were tested directly in the browsers console.

evant
12 May 2012, 10:27 PM
Why not just use getCmp? It will be a whole lot faster.

halcwb
13 May 2012, 2:11 AM
Why not just use getCmp? It will be a whole lot faster.

You're right, only I am just curious why it is not working with the hash. Actually, I just use this kind of code in the console the inspect some object or in test code.

jay@moduscreate.com
13 May 2012, 4:30 AM
Don't use static component ids. use 'itemId' or some other custom attribute instead.

börn
16 May 2012, 2:21 AM
Very funny... - i did this a second ago in firebug (i looked up the id in the dom):


>>> Ext.getCmp('genericList-1236')
Object { xtype="genericList", title="...", viewConfig={...}, mehr...}
>>> Ext.ComponentQuery.query('#genericList-1236')
[Object { xtype="genericList", title="...", viewConfig={...}, mehr...}]

and the result actually looks fine... - the only difference is, that query returns an array...

@Jay: why we shouldn't use static ids? I know it should be considered harmful if you're using components with the same id more then once accidentally and i avoid using this, but i used the static id to tie up some selenium tests to certain components, textfields, so i can check if they exist or behave like they're used to. Is itemId also accessible in the dom tree?