cancel
Showing results for 
Search instead for 
Did you mean: 

how to process passed data from another view?

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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);

  
}
});

Answers (1)

Answers (1)

PMarti
Active Participant
0 Kudos

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