Skip to Content
Former Member
Jan 28, 2014 at 05:19 PM

Binding models together in sapui5 / mapping paths between models


Hi there,

is there a possibility to keep two models in sync or define a model which is just a view to some subset of information onto another model? Assume you have a model like this

var oModelA = new sap.ui.model.json.JSONModel({
"dataInA": [
{ "name": "1st @ A" },
{ "name": "2nd @ A" }]});

and you want to have a model with a layout like this:

var oModelB = new sap.ui.model.json.JSONModel({
"globalName": "?????"});

Can we link oModelB to oModelA such that


resolves to, e.g.,


See this gist here.

You might argue: Why should we? Simply define the binding on the control such that it references "name" and use


But I'm trying to write a control which consists of several sub-controls whose properties are named differently and which I want to address from the outside with only one property name -- and I thought doing it via an internal model would be the way.



PS: To be more specific: I'm trying to write a control which yields a color field which on press yields a colorpicker which then changes the Color field -- pretty much exactly like the color picker in the DemoKit. But I would like to hide the two items (the picker and the color field indicating the selected color) within one control -- without writing all `bindProperty`, `setModel`, `unbindProperty`, `setProperty`, ... etc. myself and propagate them to the embedded controls. I was rather thinking about defining one model inside the control as CustomData and bind its properties from the outside and then use this control-local model to bind the Picker and the Color field to.