javascript - 使用工厂函数聚合绑定(bind)中的多个控件

标签 javascript data-binding sapui5 aggregation

我想在 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 中添加 titlenameInputtype为空或未定义时,titlenameText。但它返回一个错误:

Uncaught TypeError: o.setBindingContext is not a function

我不知道为什么会发生这种情况。当我们在工厂函数中仅返回单个控件而不是数组时,它会起作用。有谁知道如何使用工厂返回聚合绑定(bind)中的多个控件?

最佳答案

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

关于javascript - 使用工厂函数聚合绑定(bind)中的多个控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59051074/

相关文章:

javascript - OpenUI5/SAPUI5 中表达式绑定(bind)中的函数调用

sapui5 中的 fragment.xml 文件的本地化(i18n)未出现

sapui5 - 如何创建SAP Fiori自定义启动板?

javascript - 如何使用 localhost 在浏览器中运行 Web 应用程序?

javascript - JS : How to remove white spaces only from inside of string

c# - 为什么这个 Silverlight 附加属性不起作用?

c# - 使用 http :\\URL 的 WPF 图像 UriSource 和数据绑定(bind)

html - 将枚举绑定(bind)到 MVC 4 中的 DropDownList?

javascript - Redis/Node.js - 2 个客户端(1 个发布/订阅)导致写入问题

javascript - 如何在单击 "more"链接之前 chop 文本?