【问题标题】:Mutimodel JSON-BInding doesn´t work多模型 JSON 绑定不起作用
【发布时间】:2016-08-30 12:54:24
【问题描述】:

视图上设置了一个上下文,我想将一个属性绑定到一个标签,但该属性需要绑定到另一个模型而不是上下文。 我试过了:

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

我不知道这里的绑定有什么问题。上下文绑定正确且有效。

【问题讨论】:

  • 可以尝试运行不带函数bindProperty:return new sap.m.Label({ text: "{labelname}", visible: "{detailModel>/contextExisting}" })
  • 您可以尝试的第二件事是在您的视图中调用this.getModel("detailModel").getData() 并检查结果。
  • 标签名不是问题。这很好用。属性绑定不起作用。
  • this.getModel("detailModel") 出现错误,表明这不是函数。sap.ui.getCore().getModel("detailModel") 出现结果。
  • this 一定是你的观点

标签: javascript data-binding sapui5 jsonmodel


【解决方案1】:

以下代码必须有效:

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;

【讨论】:

    【解决方案2】:

    如果你想使用上下文,下面是正确的合成器(不带斜线)

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

    请检查您的“detailModel”的上下文是否已设置。此处不使用默认模型的上下文。

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

    或更好地防止异常

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      • 2018-08-15
      • 2018-02-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多