Javascript 聚合绑定中使用工厂函数的多个控件
我想在Javascript 聚合绑定中使用工厂函数的多个控件,javascript,data-binding,sapui5,aggregation,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) {
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];
}
}
}
});
当类型
属性中有内容时,我想在VBox
中添加标题
和名称输入
,当类型
为空或未定义时,我想添加标题
和名称文本
。但它返回了一个错误:
Uncaught TypeError: o.setBindingContext is not a function
我不知道为什么会这样。当我们只返回工厂函数中的单个控件,而不返回数组时,它就工作了。有人知道如何使用工厂返回聚合绑定中的多个控件吗?工厂函数应该只返回一个控件实例,而不是一个数组。当我在一个VBox项目中需要多个控件时,我可能会使用一个单独的xml片段(例如,另一个VBox或HBox),该片段中又有许多适当的控件