Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3255

Binding models together in sapui5 / mapping paths between models

$
0
0

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

 

oModelB.getProperty("/globalName");

resolves to, e.g.,

 

oModelA.getProperty("/dataInA/0/name");

See this gist here.

 

 

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

 

oControl.bindElement("/dataInA/0").setModel(oModelA);

 

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.

 

Thanks,

M.

 

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.


Viewing all articles
Browse latest Browse all 3255

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>