cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Array update issue

chengalarayulu
Active Contributor
0 Kudos

Hi,

I've a global Model for entire application. And a local model for one view. Array is in the global model.

1. Created view elements and binding with local model created on view

2. reading values from local model and trying to push to global model

Issue: very first element is pushing fine. But, when I try to push the second item to the global model, the first element which is already there in the model is updated with the new values entered on the screen. Am wondering, there is not binding though to global Model to get set by the framework.

Thought, to create local array in view controller itself and tried to push. Even, here also same thing is happening. when I read the model(model.getProperty) itself, the new values are directly getting updated to the model array.

var vModel = this.getView().getModel();
// Local Model
var vData = vModel.getProperty("/EduData");

var ownerComp = this.getOwnerComponent();
// Global Model 
var empModel = ownerComp.getModel("EmpData");
// Global Model Array
var EduDetails = empModel.getProperty("/Employees/EducationalInfo");

var eduModel = ownerComp.getModel("EduData"); // Local Model 
// Reading user input values
var modelData = eduModel.getProperty("/"); 

// Pushing to local Model
vData.push(modelData);
vModel.refresh();
// Pushing to Global Model 
EduDetails.push(modelData);

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

// Reading userinputvalues

var modelData = eduModel.getProperty("/"); // Pushing tolocal Model
vData.push(JSON.parse(JSON.stringfy(modelData)));
junwu
Active Contributor
0 Kudos

do the same for other push if needed.

Answers (2)

Answers (2)

chengalarayulu
Active Contributor
0 Kudos

Hi Ulrich, Thanks for coming back, binding and alias names everything is perfect. There is no error as such. But, the goal is, I want to read data from UI and push it to an array of the model. I will try to explain you bit more what is happening at the moment.

array A1 = [ { A B C }

{ X Y Z} ]

above is the data initially there in the model. Now, user is trying to add few more inputs and am reading them and adding using PUSH method.

{L M N} - this I've read from UI and pushed to A1 and L M N are added at the bottom as array element 2. first time it is fine. again user tried to add one more

{O P Q} - here onwards the issue starts. L M N will also be replaced by O P Q. All further elements will be replaced by the latest element values.

Now, the array A1 = [ { A B C }

{ X Y Z}

{O P Q}

{O P Q}] - please suggest.

0 Kudos

What is the goal of this model manipulation? Would it be possible to use named models instead? At the setModel function you could use sth like:

oControl.setModel(oModel, "yourAlias");

At the data binding part use sth like:

"yourAlias>EduData/"