PDA

View Full Version : ref property missing - what are the alternatives?



nightwatch
26 Jul 2011, 1:30 AM
Hello, what happened to 'ref' property in Sencha Touch - why isn't it supported and are there any plans to introduce it in future versions? It was extremely handy for me in Ext JS and without it I feel lost and unable to produce clean code.

Hanni Sullivan
26 Jul 2011, 2:03 AM
There was a very informative thread about it, but I can't find it anymore. To sum it up: 'ref' is not and will not be supported in Sencha Touch.

I use the itemId property in combination with the down method like this:


MyApp.View.MyPanel = Ext.extend(Ext.Panel, {

initComponent: function () {
var config = {
items: [
{
xtype: 'myXType',
itemId: 'someComponent'
}
],
controllerName: 'KoelnApp.Controller.AddressesDetailPanel'
};
Ext.apply(this, config);
MyApp.View.MyPanel.superclass.initComponent.apply(this, arguments);
var myRefAlternative = this.down('#someComponent');
}
});

jjerome
26 Jul 2011, 8:13 AM
Hanni Sullivan's alternative is good. Here is another if I am looking at this the same way:



//copying most of Hanni's code for this

var alternative;
MyApp.View.MyPanel = Ext.extend(Ext.Panel, {

initComponent: function () {
config = {
items: [
{
xtype: 'myXType',
id: 'someComponent'
}
]
};
Ext.apply(this, config);
MyApp.View.MyPanel.superclass.initComponent.apply(this, arguments);
alternative = Ext.getCmp('someComponent');
}
});

Hanni Sullivan
26 Jul 2011, 10:49 PM
@jjerome: While your solution certainly works, i would advise against using id since afaik it has to be a unique value. Unique across your whole app to be exact. If you instantiate the 'myXType' component more then once you'll likely run into trouble with your approach. The itemId property on the other hand exists only in a 'local' scope which makes it the preferable solution.

jjerome
27 Jul 2011, 3:55 PM
Yes, thanks for the input. I never ran into that issue because as of now all my components were unique so I stuck with setting the id since the programs run a little faster ( Instead of having to query the whole program with 'down' )

Hanni Sullivan
27 Jul 2011, 11:09 PM
There is a performance penalty when using itemId and the Component query? Interesting!

But you don't have to query the whole program. If you take a look at my example, the query will only search inside the panel which should be quite fast.