Skip to Content
0

SAPUI5 Binding Events

Oct 19, 2016 at 12:23 PM

178

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

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

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks, this solved the issue!

1
Joseph BERTHE Sep 06, 2017 at 09:14 PM
0

Hello,

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

Regards,

Share
10 |10000 characters needed characters left characters exceeded