Skip to Content
0

Passing Parameters one view to another view in xml

Apr 18, 2017 at 07:11 AM

59

avatar image
Former Member

Hi Professionals,

I'm working on the "Passing Parameters one view to another view in xml view". I have done all but in the last error is appearing in "setModel(oModel)". Here is my code

onInit : function() { var oModel = new sap.ui.model.json.JSONModel("z/product.json"); this.getView().setModel(oModel);

},

onTablePress : function(oEvent){ var that = this; var oModel = new sap.ui.model.json.JSONModel(); sap.ui.getCore().setModel(oModel, "Name"); var x = []; for (var i = 0; i<oEvent.oSource.mAggregations.cells.length; i++) { x [i] = oEvent.oSource.mAggregations.cells[i].mProperties.text; } var oRouter = sap.ui.core.UIComponent.getRouterFor(that); oRouter.navTo("navtable"); oModel.setData(x); var oMax = this.getView("zdemo_table.zdemo_table.navtable").byId("idObjectHeader").setModel(oModl);

},

Please any one help me out from this problem.

thank you in advance.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Akhilesh Upadhyay Apr 18, 2017 at 07:36 AM
0

remove last line in onTablePress function, and get the model in onInit function of second view (navigated view) controller as,

var oModel = sap.ui.getCore().getModel("Name");

//now set oModel to your view/control here

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Akhilesh,

Thank you, for your answer. As per your mentioned I have done, but it is not working.

onInit : function() {

var oModel = new sap.ui.model.json.JSONModel("zd/product.json"); this.getView().setModel(oModel);

var oMode = this.getView().getModel("z.z.table");

var oM = oMode.setModel(oModel);

},

this is my second view controller it is also binded with the json.

Please see the error in below screen short.

capture.png (117.1 kB)
0

you are doing wrong! this is not the right way to do this, but in your case flow would be as below:

get/prepare data in first view -> set data to a model in first view-> set model to core in first view-> get and set model in second view -> binded data will be shown in second view

As you have already set a named model "sap.ui.getCore().setModel(oModel, "Name");" in first view.

Now,

in second view onInit function write below code only

var oModel = sap.ui.getCore().getModel("Name");

// in debug mode you can verify whether you are getting model and respective data or not

this.getView().setModel(oModel);

1
VIPLOVE KHUSHALANI Apr 19, 2017 at 10:01 AM
0

Hi

Instead of accessing the model you can even pass the data in navigation .

Just check out the navigation example : https://sapui5.hana.ondemand.com/explored.html#/entity/sap.ui.core.tutorial.navigation/samples

thanks

Viplove

Share
10 |10000 characters needed characters left characters exceeded