cancel
Showing results for 
Search instead for 
Did you mean: 

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

former_member243729
Participant
0 Kudos

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.

former_member243729
Participant
0 Kudos

These are the attributes of Types object. Out of these attributes I want to assign 'abc' to 'value' attribute.

I got below data using

this.getView().getModel().getProperty("/types/1")

former_member365727
Active Contributor

use this code in console...

this.getView().getModel().setProperty("/types/1/value", "abc");

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member365727
Active Contributor

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
former_member243729
Participant
0 Kudos

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")