I've tried different demo application of SAPUI5 like shoping cart, manage product. But I"m unable to solve my problem. I've two views. on home view I've set my model globally like
var model = this.getView().getModel('product');
var oModel = new sap.ui.model.json.JSONModel(model);
sap.ui.getCore().setModel(oModel, "product");
and then I'm navigating to product page. where i'm accessing my product name and trying to access my specific product to bind with my current view.
_routePatternMatched: function(oEvent) {
var name= oEvent.getParameter("arguments").name,
oView = this.getView(),
sPath = "/Product('" + sId + "')";
console.log(sPath);
var oModel = sap.ui.getCore().getModel("product");
var oData = oModel.getData(sPath);
console.log(oData);
oView.bindElement({
path: sPath,
events: {
dataRequested: function() {
oView.setBusy(true);
},
dataReceived: function() {
oView.setBusy(false);
}
}
});
//if there is no data the model has to request new data
if (!oData) {
oView.setBusyIndicatorDelay(0);
oView.getElementBinding().attachEventOnce("dataReceived", function() {
// reset to default
oView.setBusyIndicatorDelay(null);
this._checkIfCourseAvailable(sPath, name);
}.bind(this));
}
},
_checkIfCourseAvailable: function(sPath) {
var oModel = sap.ui.getCore().getModel("product");
var oData = oModel.getData(sPath);
// show not found page
if (!oData) {
this._router.getTargets().display("notFound");
}
},
I got the right result by filtering by id. now after giving path to var oData = oModel.getData(sPath);
console.log(oData);
It have the right result but i'm unable to it do not show data on view i'm trying as {pruduct>/name}