Skip to Content

SAPUI5 Array update issue


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
// Pushing to Global Model 
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Mar 13, 2017 at 04:29 PM

    // Reading userinputvalues

    var modelData = eduModel.getProperty("/"); // Pushing tolocal Model
    Add comment
    10|10000 characters needed characters exceeded

  • Mar 13, 2017 at 03:57 PM

    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:

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 13, 2017 at 04:08 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded