我想在 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
中添加 title
和 nameInput
当type
为空或未定义时,title
和nameText
。但它返回一个错误:
Uncaught TypeError: o.setBindingContext is not a function
我不知道为什么会发生这种情况。当我们在工厂函数中仅返回单个控件而不是数组时,它会起作用。有谁知道如何使用工厂返回聚合绑定(bind)中的多个控件?
最佳答案
工厂函数应该只返回一个控件实例,而不是一个数组。当我需要在一个 VBox 项目中使用多个控件时,我可能会使用一个单独的 xml 片段(例如另一个 VBox 或 HBox),其中又包含许多适当的控件。
关于javascript - 使用工厂函数聚合绑定(bind)中的多个控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59051074/