【问题标题】:Multiple controls in the aggregation binding using factory function使用工厂函数的聚合绑定中的多个控件
【发布时间】:2020-03-21 21:08:05
【问题描述】:

我想在VBox 控件的items 聚合中包含多个控件。

var title = new sap.m.Title({text: "Name"});
var nameInput = new sap.m.Input();
var nameText = new sap.m.Text();

var layout = new sap.m.VBox({
    items: {
        path: "/",
        factory: function(sId, oContext) {
            var type = oContext.getProperty("type");
            if (type) {
                 return [title, nameInput];
            } else {
                 return [title, nameText];
            }
        }
    }
});

type 属性中有内容时,我想在VBox 中添加titlenameInput,当type 为空或未定义时,我想添加titlenameText。但它返回一个错误:

Uncaught TypeError: o.setBindingContext is not a function

我不确定为什么会这样。当我们在工厂函数中只返回单个控件而不是数组时,它可以工作。有谁知道如何使用工厂在聚合绑定中返回多个控件?

【问题讨论】:

    标签: javascript data-binding sapui5 aggregation


    【解决方案1】:

    Factory 函数应该只返回一个控件实例,而不是数组。当我在一个 VBox 项中需要多个控件时,我可能会使用一个单独的 xml Fragment(例如另一个 VBox 或 HBox),其中又包含许多适当的控件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-23
      • 1970-01-01
      • 2015-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多