0
votes

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.

2

2 Answers

0
votes

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)); 
}
0
votes

If usage of sap.m.Page is an option than navButtonPress builtin event can be used:

View.xml:

<mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc">
    <Page navButtonPress="onNavBack">
    ...

Controller.js:

    onNavBack: function(oControlEvent) {
        var oController = this;
        var oView = this.getView();
    }

the event listener will be triggered every time the button is pressed in the Fiori Launchpad header.