Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get passed data on next page after calling "to" from NavContainer

Tags:

sapui5

I am on my way building a Fiori like app using SAPUI5. I have successfully built the Master page, and on item click, I pass the context and navigate to Detail page.

The context path from Master page is something like /SUPPLIER("NAME"). The function in App.controoler.js is as follows:

handleListItemPress: function(evt) {
  var context = evt.getSource().getBindingContext();
  this.myNavContainer.to("Detail", context);
  // ...
},

But I would like to know how I can access this context in the Detail page. I need this because I need to use $expand to build the URL and bind the items to a table.

like image 688
Sangamesh Hs Avatar asked Nov 24 '22 01:11

Sangamesh Hs


1 Answers

There is an example in the UI5 Documentation on how to deal with this problem using an EventDelegate for the onBeforeShow function which is called by the framework automatically. I adapted it to your use case:

this.myNavContainer.to("Detail", context); // trigger navigation and hand over a data object
// and where the detail page is implemented:
myDetailPage.addEventDelegate({
  onBeforeShow: function(evt) {
    var context = evt.data.context;
  }
});

The evt.data object contains all data you put in to(<pageId>, <data>). You could log it to the console to see the structure of the evt object.

like image 118
Tim Gerlach Avatar answered May 22 '23 11:05

Tim Gerlach