namita kalita namita kalita - 7 months ago 21
Javascript Question

how to push data to existing sapui5 model

I have a Json Model in sapui5 as - //console.log(dModel);

enter image description here

My new data response is as follows - //console.log(response);

enter image description here

Now I want to push new data(only the data part) to the existing model, inside /modelData/data.

code I am trying -

sap.ui.getCore().getModel().getProperty("/modelData/data").push(response.data);


This code is pushing the data but as -

enter image description here

After 19(old values) it is pushing all the objects inside 20th as 0, 1, 2... The Ideal way should be after 19 I should get 20, 21, 22 and so on.

What changes I need to make to get this, Thank you ... please suggest.

Answer

Try this:

    for(var i = 0; i < response.data.length; i++){

       sap.ui.getCore().getModel().getProperty("/modelData/data").push(response.data[i]) 

    }