How to pass data from home page to SAPUI5 detail page?
I want to pass parameters from master page to detail page when ListItem is clicked
handleListItemPress : function (evt ) {
imp = evt.getSource().getTitle();
alert(imp);
// var mystring = 'this,is,an,example';
var splits = imp.split(",");
dino = splits[0]; //I want to send three parameters
revno = splits[1];
uruntipi = splits[2];
var context = evt.getSource().getBindingContext();
this.nav.to("Detail", context);
},
I want to get a parameter options page onInit
.
+3
source to share
2 answers
handleListItemPress: function (evt) {
var imp = evt.getSource().getTitle(); //don't declare globals variables
// var mystring = 'this,is,an,example';
var splits = imp.split(",");
//build json object with all your properties you want to send
var context = {
dino: splits[0],
revno: splits[1],
uruntipi = splits[2],
bindingContext = evt.getSource().getBindingContext()
};
this.oRouter.navTo("Detail", context);
//OR sap.ui.core.UIComponent.getRouterFor(this).navTo("Detail", context);
//this.nav.to("Detail", context);
}
Detail Page:
onInit: function () {
var oRouter = sap.ui.core.routing.Router.getRouter("appRouter");
//can also use directly this.oRouter.attachRouteMatched(...)
oRouter.attachRouteMatched(function (oEvent) {
if (oEvent.getParameter("name") !== "detail") {
return:
}
var dino = oEvent.getParameter("arguments").dino;
var revno = oEvent.getParameter("arguments").revno;
var uruntipi = oEvent.getParameter("arguments").uruntipi;
var bindingContext = oEvent.getParameter("arguments").bindingContext;
}, this);
}
More details here Methods and events for navigation
+4
source to share
If you don't want to use routing, you can use the event bus. https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.core.EventBus.html
In master, when you have parameters to pass, write:
this.bus = sap.ui.getCore().getEventBus();
this.bus.publish("channel1", "eventA" , {
par1: 4324,
par2: 23423,
par3: 12331
});
In the part controller, in the init function, add:
this.bus = sap.ui.getCore().getEventBus();
this.bus.subscribe("channel1", "eventA", this._manageData, this);
and add a function:
_manageData: function (channel1, eventA, data) {
//here data contains par1, par2, par3
},
But the correct way to use the same data in a larger view is to use a model (JSONModel ...)
+1
source to share