Skip to Content

In SAPUI5 code how to set value to an Object property in model ?

I have below code which gets me 5 objects which are present in the model

var b = this.getView().getModel().getData().types;

When I check b[1].value I get empty value, which is fine.

Now I want to make the empty value to something like "abc" and put it back to the model. Can I know how can I put it back to the model ? Please assist.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Mar 03, 2017 at 12:08 AM

    Assuming this is ODATA model, you can use setProperty method

    var oModel = this.getView().getModel();
    oModel.setProperty("/types/1", "abc"); //path is referring to element in array with index 1
    Add comment
    10|10000 characters needed characters exceeded

    • Thanks. Need some more help.

      There are 5 objects in Types. And each object has 4 attributes. One of the attribute is 'value'. So I basically want to set the value like..

      Types[1]-->value = "abc".

      Will the below code work ?

      oModel.setProperty("/types/1/value", "abc")