Skip to Content

how to process passed data from another view?

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Dec 24, 2014 at 06:34 AM

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 24, 2014 at 11:38 PM

    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

    Add comment
    10|10000 characters needed characters exceeded