Skip to Content
avatar image
Former Member

OData model binding read / write

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jun 28, 2014 at 01:46 PM

    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

    Add comment
    10|10000 characters needed characters exceeded