多模型 JSON-BInding 不起作用



在视图上有一个上下文集,我想将属性绑定到Label,但该属性需要绑定到另一个模型而不是上下文。我试着:

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

也尝试:

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

:

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

和JSONModel:

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

模型被全局设置为:

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

模型不是在同一个。view中创建的,但是我可以在相关视图中使用:

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

我不知道这里的绑定有什么问题。

以下代码必须有效:

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;

如果您想使用上下文,下面是正确的语法(没有斜杠)

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

请检查"detailModel"的上下文是否已设置。这里没有使用默认模型的上下文。

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

或更好地防止异常

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