-1

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 .

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
RenPen
  • 63
  • 1
  • 1
  • 6
  • You can try to run is without the function `bindProperty`: `return new sap.m.Label({ text: "{labelname}", visible: "{detailModel>/contextExisting}" })` – herrlock Aug 30 '16 at 13:03
  • The second thing you can try is to invoke `this.getModel("detailModel").getData()` in your view and check the result. – herrlock Aug 30 '16 at 13:05
  • The labelname is not the Problem. That works fine. The Property-Binding doesn´t work. – RenPen Aug 30 '16 at 13:05
  • With `this.getModel("detailModel")` there is an error that says that that´s not a function.With `sap.ui.getCore().getModel("detailModel")` there is a result. – RenPen Aug 30 '16 at 13:12
  • `this` must be your view – herrlock Aug 30 '16 at 13:14
  • ok tried this instat of `this` : `console.log(sap.ui.getCore().byId("detail").getController().getView().getModel("detailModel"));` result is `undefined` – RenPen Aug 30 '16 at 13:16
  • Then I suppose your model is not inherited by the view – herrlock Aug 30 '16 at 13:31
  • Working Example: https://jsbin.com/seforoyoyi/edit?html,output – herrlock Aug 30 '16 at 13:33
  • 1
    Thanks verry much. It is working now. In place of `sap.ui.getCore().setModel` I´m now using `this.setModel` on the view. So that `this.getModel` is not longer`undefined`. But I still don´t understand why `sap.ui.getCore().setModel` doesn´t work because in my understanding with `sap.ui.getCore().setModel` is set a Model globally so that i can fetch this in any view within the app... . – RenPen Aug 31 '16 at 09:02

2 Answers2

0

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;
Daniël Camps
  • 1,737
  • 1
  • 22
  • 33
0

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());