Mutimodel JSON-BInding doesn´t work

111 views Asked by At

there is a context set on the view and I want to bind a property to a Label but that property needs to be bind to another model than the context. I tried:

createLabel: function (){
  return new sap.m.Label({
      text: {labelname}
  }).bindProperty("visible","{/contextExisting}","detailModel");

also tried:

.bindProperty("visible","{detailModel>contextExisting}");

and:

.bindProperty("visible","{detailModel>/contextExisting}");

and the JSONModel:

this._detailJSONModel.setData({"contextExisting" : false});

the model is set globally with:

sap.ui.getCore().setModel(this._detailJSONModel,"detailModel");

The Model isn´t created in the same .View but I can reach the model in the relevant view with:

sap.ui.getCore().getModel("detailModel");

I don´t know what´s wrong with the binding here. The Context-Binding is correct and working .

2

There are 2 answers

0
Daniël Camps On

The following code must work:

var label = new sap.m.Label({
      text: {labelName}
  }).bindProperty("visible",
{path : "detailModel>/contextExisting",
formatter: function(x){
console.log(x); //should read 'false'
return x;
}});

console.log(label); //check here. What models do you see in the 'oModels' 
                    //property, and the 'oPropagatedProperties/oModels' property? One of these must 
                    //contain your model.

return label;
0
Markus Bauernschmitt On

If you want to use a context, following is the correct synthax (without a slash)

.bindProperty("visible","{detailModel>contextExisting}");

Please check that the context of your "detailModel" is set. The context of default model isn`t use here.

$.sap.log.info(label.getBindingContext("detailModel").getPath());

or better to prevent exceptions

$.sap.log.info(label.getBindingContext("detailModel") && label.getBindingContext("detailModel").getPath());