Search code examples
javascriptextjssencha-touch-2

Up method is not working correctly in Sencha Touch


I am working with Sencha Touch and I have the next codeline

var formpanel = button.getParent().getParent().down('formpanel'); //working correctly but tricky

I am using two "getParent()" because the "up" method is not working for me

var formpanel = button.up('formpanel'); //No-working

and the view

items: [
            {
                xtype: 'toolbar',
                title: 'test',
                docked: 'top',
                items: [{
                    xtype: 'button',
                    iconCls: 'info',
                    style:{
                        'margin-left': '75em'
                    }
                }]
            },
            {
                xtype: 'formpanel',
                layout: 'hbox',
                scrollable: null,
                items: []
            }

Any clue?

Thanks


Solution

  • It will not work because according to sencha docs:

    up( [selector] ) :Walks up the ownerCt axis looking for an ancestor Container which matches the passed simple selector.

    So, in your case button's ancestors are the toolbar and the parent of toolbar,but not the formpanel.Using up() you can get toolbar or parent of toolbar, but not the formpanel.Instead of that you can use following codes:

    First Code

    var formpanel = button.up(<XtypeOfToolbarParent>).down('formpanel');
    

    OR

    Second Code: similar to getParent()

     var formpanel = button.up().up().down('formpanel');