简体   繁体   English

如何通过列表SAPui5上带有标签的对话框中的复选框绑定属性(选中)

[英]How to bind property (checked) from checkbox in dialog with label on the column table, SAPui5

i have a view, which contains table; 我有一个视图,其中包含表格; with onclick event dialog pops up with checkboxes in it. 带有onclick事件对话框的对话框会弹出。 When user checkes boxes, the same columns(as checkboxes) should be added to the table. 当用户选中复选框时,应将相同的列(与复选框相同)添加到表中。 How to bind properties of checkbox (checked: true) with column(setVisible) ? 如何将复选框(选中:true)的属性与column(setVisible)绑定? Thank you! 谢谢!

ex of checkbox: 复选框前:

var tv3 = new sap.ui.commons.CheckBox({
    text : 'Equipment Tag',
    checked: false,
});

one of the tablecolumn 桌栏之一

table.addColumn(new sap.ui.table.Column({
    label : new sap.ui.commons.Label({
        text : "Functional Location"
    })
}));

You're asking how to bind checkbox selections in a dialog with visibility of columns in a table. 您要问的是如何在具有表中列可见性的对话框中绑定复选框选择。 You can use a JSON model to achieve this: 您可以使用JSON模型来实现此目的:

  • have visibility properties for each of the columns you want bind 具有要绑定的每个列的可见性属性
  • those model properties to the visible property of each column control 这些模型属性改为每个列控件的visible属性
  • bind those model properties also to the checkbox control's selected property 还将那些模型属性绑定到复选框控件的selected属性

The two-way binding will mean that the effect is achieved. 双向绑定将意味着达到效果。 I've written a working example with a JSON model, commons Table, Columns and CheckBox controls in a Dialog for you to see. 在对话框中编写了一个JSON模型,commons Table,Columns和CheckBox控件工作示例,供您查看。

Here are the salient parts: 以下是主要部分:

Visibility in JSON model: 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" }
    ] 
}));

Visibility binding on Column: 列上的可见性绑定:

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}" })
}),

Visibility binding on CheckBox: CheckBox上的可见性绑定:

new sap.ui.commons.CheckBox({
    text: "First Name",
    checked: "{/visibleColumns/firstName}"
})

Bonus: You may be interested in the TablePerso* mechanism set in the sap.m library which does a similar thing for column visibility. 奖励:您可能对sap.m库中设置的TablePerso *机制感兴趣,该机制为列可见性做了类似的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM