Skip to Content

SAPUI5 Binding Events

Hi there.

I've a sap.m.ComboBox which I bind items to, and use the binding events to show a busy indicator while data is retrieved (and hide it when done). However, the binding events are triggered also on selection of a list item in the ComboBox and I don't want to show the busy indicator then. But I can't access anything but the ComboBox in the event functions.

I've a sap.m.ComboBox in my XML view, below it is called oDropDown:

oDropDown.bindItems({
    path: ipType,
    template: this._oTemplate,
    events: {
        dataRequested: function(oEvent){
            			oDropDown.setBusy(true);
        },
        dataReceived: function(oEvent){
            			oDropDown.setBusy(false);
        }
    }
});

This code works fine, the busy indicator is shown and hidden as expected.

However, because these events are called also when a selection is made in the ComboBox, I want to have a condition (because I want to show a MessageToast when the list is updated, but not show it when only a selection is made).

I've a variable set on "this" (controller) which is true/false, however "this" inside the event functions is not the same "this" as in the bindItems. (in bindItems, "this._oTemplate" is using the "this" I want to use, but if I use "this" inside the dataRequested event function, it's a different "this", if you get me...

It's the exact same issue even if I use outside functions,

oDropDown.bindItems({
    path: ipType,
    template: this._oTemplate,
    events: {
        dataRequested: fnOnDataRequested,
        dataReceived: fnOnDataReceived
        }
    }
});

The "this" inside fnOnDataRequested is not the "this" (controller).

If I set "that = this" before I bind the items, "that" is "undefined" inside the event functions.

Hopefully I make myself understood, and hopefully someone out there would know a way to do this? To access "this" (controller) inside the event functions.

Thanks,
Thomas

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 12, 2017 at 09:50 AM

    Hi Thomas,

    PFB the updated code:

    oDropDown.bindItems({
        path: ipType,
        template: this._oTemplate,
        events: {
            dataRequested: fnOnDataRequested.bind(this),
            dataReceived: fnOnDataReceived.bind(this)
            }
        }
    });

    After doing this, the functions fnOnDataRequested and fnOnDataReceived will be binded to the "this" of current context, i.e. your controller and you can access all your controller variable inside these functions.

    Regards,

    Rahul

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 06, 2017 at 09:14 PM

    Hello,

    Why would not you just do the event attachment on Model events ? And not in dropdown control ?

    Regards,

    Add comment
    10|10000 characters needed characters exceeded