Skip to Content

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

Mar 02, 2017 at 11:58 PM


avatar image

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.

10 |10000 characters needed characters left characters exceeded

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

I got below data using


untitled.png (21.9 kB)
untitled.png (21.9 kB)

use this code in console...

this.getView().getModel().setProperty("/types/1/value", "abc");
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Srikanth KV 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
Show 1 Share
10 |10000 characters needed characters left 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")