on 12-23-2014 7:39 AM
hi,
iam performing an odata read from controller of ,say view1 and passing data to another view like below
OData.read({ requestUri:
"url",
headers: { "X-Requested-With": "XMLHttpRequest", "sap-user" : username, "sap-password" : password, "Content-Type": "application/atom+xml" },
},
function (data) {
var oModel = new sap.ui.model.json.JSONModel();
var myData = {};
myData.Products = data.results;
oModel.setData(myData);
sap.ui.getCore().setModel(oModel);
// sap.ui.getCore().setModel(oModel, "mydashboardModel");
sap.ui.core.BusyIndicator.hide();
// sap.ui.getCore().getModel("mydashboardModel").updateBindings(true);
app.to("Dashboard",data);
},
function(err){
// window.alert("error: "+ err.message);
// bsydialog.close();
sap.ui.core.BusyIndicator.hide();
window.alert("error");
}
);
how to access or just print the mydata array in another view called view2
It seems you're reading the oData and creating a json model & setting it to the core. So, you just can access the model by doing,
sap.ui.getCore().getModel();
Fyi, if the model is set to the core, it can be accessed from any part of the app.
Say, when you wanna access data that you pass during the navigation,
app.to("Dashboard",data);
In the Dashboard controller, you'll have to define
dashboardPage.addEventDelegate({
onBeforeShow: function(evt) {
console.log(evt.data);
}
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi rajeesh,
I show you an example to how to pass data between different views: JS Bin Example
If you are setting a model into the core, you can retrieve data from any part of application as follow:
var data = sap.ui.getCore().getModel("mydashboardModel").oData;
Regards,
Pau
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.