0
votes

i have a custom control which need to array of data as below

properties : {
            scrollheight: {type : "sap.ui.core.CSSSize", defaultValue : "100%"},
            array1 :{type : "Array", defaultValue : []},
            array2 : {type : "Array", defaultValue : []},
        }

and i have 3 JSONModel which i have set to the View

Problem is i need to process these model and i have to make 2 arrays to set to the Custom control.

When any change happen to these JSONModels i need to update the array also.

How can i achieve this, if i bind these to property? or do i need to listen the changes to the model and update the array?

or is their any other method of doing it?

2

2 Answers

0
votes

It is sometimes tough to keep the data in your JSONModel consistent from the controller, as you always have to remember that if you change one thing, you also have to change the other.

To make controller code less cluttered, I usually create a subclass of JSONModel in which I take care of the model consistency. This can be accomplished by overriding the setProperty method with your own, and when you see that a certain property is edited, dependent properties are immediately changed as well.

Please find an example of how this could work in the jsbin below. In the example I'm trying to keep property 2 consistent with property 1:

http://jsbin.com/novepa/1/edit?html,output

0
votes

i solved this by getting the binding and attaching change event

We have to get the binding for particular item in the Model if its property we can take PropertyBinding if its List or array we have to take ListBinding

and then i have one model which is set to the Custom Control and change event will update the Custom control model

JSBin which shows how to add the change event to binding(Here i used ListBinding)