1. #1
    Sencha User
    Join Date
    Oct 2012
    Location
    San Francisco
    Posts
    13
    Answers
    1
    Vote Rating
    0
    antun is on a distinguished road

      0  

    Default Unanswered: Question on referencing objects inside of a view

    Unanswered: Question on referencing objects inside of a view


    I'm new to Sencha (using 4.1.1), so this is probably a very basic quesion. In the code example below, why is a a reference to the panel, and b undefined? Is there a different method I need to use to reference a nested object?

    Code:
    Ext.define('SFC.view.flashcard.Show' ,{
        extend: 'Ext.container.Container',
        alias : 'widget.flashcardshow',
    
    
        layout: 'fit',
    
    
        title : 'Flashcard TODO',
    
    
        store: 'SpanishWords',
    
    
        items : [
            {
                itemId: 'flashWord',
                xtype: 'panel',
                layout: 'hbox',
                title: 'Spanish Flashcards',
                items: [
                    {
                        xtype: 'text',
                        itemId: 'foobar',
                        text: 'palabra'
                    }
                ]
            }
        
        ],  
    
    
        initComponent: function() {
            this.callParent(arguments);
        },
    
    
        updateWord: function(newWord) {
            // THIS WORKS:
            var a = this.getComponent("flashWord");
            console.log(a);
    
    
            // THIS DOES NOT:
            var b = this.ownerCt.getComponent("foobar");
            console.log(b);
        }
    });
    Thanks,

    Antun

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,987
    Answers
    464
    Vote Rating
    649
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    this refers to

    Code:
    SFC.view.flashcard.Show
    getComponent gets a direct child by id, so that's why a works.

    In the second case, you're asking for the parent of

    Code:
    SFC.view.flashcard.Show
    Then trying to get a single child component with an id of foobar, which, obviously, doesn't exist.

    If you did:

    Code:
    var b = a.getComponent("foobar");
    It should work.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Location
    San Francisco
    Posts
    13
    Answers
    1
    Vote Rating
    0
    antun is on a distinguished road

      0  

    Default


    Thank you for the explanation. It works for me now. I ended up doing:

    this.getComponent("flashWord").getComponent("foobar");

    Is there a way to get around having to step through the hierarchy? e.g. an equivalent of getElementById?

    Thanks,

    Antun

Thread Participants: 1