我有一个视图,其中包含表格;使用onclick事件对话框弹出复选框。当用户选中复选框时,应将相同的列(作为复选框)添加到表中。如何将checkbox(checked:true)的属性与column(setVisible)绑定? 谢谢!
ex复选框:
var tv3 = new sap.ui.commons.CheckBox({
text : 'Equipment Tag',
checked: false,
});
其中一个表列
table.addColumn(new sap.ui.table.Column({
label : new sap.ui.commons.Label({
text : "Functional Location"
})
}));
答案 0 :(得分:4)
您正在询问如何在对话框中绑定复选框选项,并在表格中显示列的可见性。您可以使用JSON模型来实现此目的:
双向绑定意味着实现了效果。我写了working example with a JSON model, commons Table, Columns and CheckBox controls in a Dialog给你看。
以下是显着部分:
JSON模型中的可见性:
sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel({
visibleColumns: {
firstName: true,
lastName: true
},
names: [
{ firstName: "DJ", lastName: "Adams" },
{ firstName: "Joseph", lastName: "Adams" }
]
}));
列上的可见性绑定:
new sap.ui.table.Column({
visible: "{/visibleColumns/firstName}",
label: new sap.ui.commons.Label({ text: "First Name" }),
template: new sap.ui.commons.TextView({ text: "{firstName}" })
}),
CheckBox上的可见性绑定:
new sap.ui.commons.CheckBox({
text: "First Name",
checked: "{/visibleColumns/firstName}"
})
奖励:您可能对sap.m库中设置的TablePerso *机制感兴趣,该机制对列可见性执行类似操作。