1

I am wondering if there is a way to access components in Sencha Touch and ExtJS without component query. And without building object structure by myself.

If I create a view like this:

Ext.Viewport.add({
    xtype: 'panel',
    itemId: 'panel1',
    modal: true,
    centered: true,
    items: [{
        xtype: 'button',
        itemId: 'btn1',
        text: 'One'
    }, {
        xtype: 'button',
        itemId: 'btn2',
        text: 'Two'
    }]
});

And to get btn2 I would rather use Ext.Viewport.panel1.btn2 over Ext.Viewport.down('#panel1').down('#btn1').

Is is possible to do this manually. But it's not pretty.

Ext.Viewport.panel1 = Ext.Viewport.down('#panel1');
Ext.Viewport.panel1.btn1 = Ext.Viewport.panel1.down('#btn1');
Ext.Viewport.panel1.btn2 = Ext.Viewport.panel1.down('#btn2');

ItemId needs to be unique between siblings it is the perfect property to use for this. Is there already an automated way that I can use? I did not find it in the documentation. Or should I just write a simple script that creates this?

drinovc
  • 521
  • 5
  • 16
  • 1
    I believe using the `down` method is the standard way of retrieving components before Ext JS 5 was released. If you upgraded your Sencha Touch application to use Ext JS 6, you could easily achieve this by adding a `reference` configuration to an item and then calling the `lookupReference` method inside a `ViewController`. – Monica Olejniczak Dec 25 '15 at 05:03
  • @MonicaOlejniczak that is true. But there is no "Object oriented" access to this. Method `lookupReference` still requires a String for fetching component. I can do this by myself but I thought that there is something like this already implemented in the framework. I guess not. – drinovc Dec 28 '15 at 12:25

0 Answers0