Paul
Paul

Reputation: 1066

Extjs retrieve label beforerender

I'm trying to load the text of a label on the beforerender event. So I attached the beforender event... as below

{
    xtype: 'label',
    text: 'VOID',
    listeners: {
        beforerender: {
        fn: me.onLabelBeforeRender,
        scope: me
    }
},

Ext.Ajax.request({
    url: '/who',
    method: 'GET',
    params: {
        id: 1
    },
    success: function(response){
        var text = Ext.decode(response.responseText);
        alert(text);
        // process server response here
    }
});

And now I would like to change the label from VOID into the response value of /who However I fail to see how I can access that label in a decent way. Of course I can add an id use getcmp however that seems so clumsy, or is that the way to go?

Upvotes: 2

Views: 6865

Answers (2)

Izhaki
Izhaki

Reputation: 23586

Actually, as far as performance goes, an id + Ext.getCmp() is the most efficient option. See this question for more.

It will definitely be faster than adding a listener, for which you get quite a healthy call stack.

Upvotes: 2

Parv Sharma
Parv Sharma

Reputation: 12705

define the label like this

{
    xtype: 'label',
    text: 'VOID',
    itemId:'someLabel',
    listeners: {
        beforerender: {
        fn: me.onLabelBeforeRender,
        scope: me
    }
}

now because you are keeping the scope as me which im assuming is some ancestor of label so with in the onLabelBeforeRender function you can access me by the this keyword. so in that function retrieve the label as

var label = this.down('label[itemId="someLabel"]');
label.setText('WHATEVER YOU WANT HERE');

Upvotes: 0

Related Questions