Search code examples
sapui5

Getting the oData in the event handler of Fiori Launchpad header event


I would like to check for data changes when the user clicks on the back button in the Fiori Launchpad. I have the following code

onAfterRendering: function() {
        sap.ui.getCore().byId("backBtn").attachPress(this, function(oEvent) {
            oEvent.preventDefault();
        }); 
}

Within the function I would like to access the oData and other variables of the main controller. However when I press the back button the "this" object is the header control's view.

How can get the view of the page content and also access the oData and other parameters of the controller associated to the content view.


Solution

  • In order to access the current context you have to call the event handler function within that specific context, so therefore a binding is needed on that function.

    onAfterRendering: function() {
            sap.ui.getCore().byId("backBtn").attachPress(this, function(oEvent) {
                oEvent.preventDefault();
            }.bind(this)); 
    }