cancel
Showing results for 
Search instead for 
Did you mean: 

OData model binding read / write

Former Member
0 Kudos

Dear Experts,

For an internal training in my company I am trying to make a prototyp using Northwind OData service. As you would now you can only read data using Northwind service. I want to show examples about deleting and adding items. What would the best approach to do this? Deleting and adding should be of course only faked in the UI and not persisted. For example like in Approve Purchase Orders example. Can I clone the model and work on it? I realized that I couldn't even call oModel.setData using Northwind. I would be happy about every input and suggestions.

Thanks and Regards,

Koray

Accepted Solutions (1)

Accepted Solutions (1)

former_member9607
Active Participant
0 Kudos

Hi Koray,

For training purpose I will suggest you,

For Read Operation:

Use Northwind service for getting data into JSON Model. Keep binding mode for JSON model as "TwoWay"



var oModel = new sap.ui.model.json.JSONModel();

oModel.setDefaultBindingMode("TwoWay");


For Delete Operation:

Take the JSON model data into an array.


var data = oModel.getData();

You can remove records from array using splice() method.


data.splice(index,1); // You may need to use data.value.slice when using Northwind service


For Insert Operation:

You can insert a record into array using push() method.


data.push('Tom');

As we have declared our model binding mode as "TwoWay", means from model to view and vice versa, whatever operation you will perform on array it will take effect on model data as well(locally).

Hope it will help you.

Regards,

KK

Former Member
0 Kudos

Thx for the tips. I did it as you described and it works!

Answers (0)