Skip to Content

Both original and delta data models getting change

Hi experts,

I am able to display the data in table from odata model uisng oModel.read method.

oModel.read("/cpdata",

{

filters: filtersArray,

success: function(oData, response){

var jModel = new sap.ui.model.json.JSONModel(oData.results);

this.getView().setModel(jModel,"set1");

this.getView().setModel(jModel,"set2");

oTable.bindRows("set1>/");

},

error: function(oError){

} });

The above code is working fine. In the table level, there is a input field where user can change the value. When the value is changed then that changed value should be compared with the set2 data model. But when i check set2 Data, it is also getting changed when user is changing the value at table level.

The value of set1 data model which is bound to table should change but not set2 data model. How to achieve this?( the intention is to compare original and delta models)

thanks

sashi

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Sep 22, 2017 at 12:19 AM

    you only have one copy of data, that's why "they" both got changed.

    var dataCopy=JSON.parse(JSON.stringify(oData.results));

    var jModel2 = new sap.ui.model.json.JSONModel(

    dataCopy

    );

    this.getView().setModel(jModel2,"set2");

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 22, 2017 at 02:52 AM

    Firstly, avoid doing binding inside the data call.

    Get the data from the service call into a local model in the success function of the oData call by creating two copies of the model.

    var jModel, kModel;
    oModel.read("/cpdata",
    {
    filters: filtersArray,
    success: function(oData, response){
      jModel = new sap.ui.model.json.JSONModel(oData.results);
      kModel = new sap.ui.model.json.JSONModel(oData.results);
    },
    error: function(oError){
    } 
    });
    //Now, both should a separate copy of data and you should be able to compareand work. 

    Regards,

    Sharath

    Add comment
    10|10000 characters needed characters exceeded