如何在sap UI5中选择所有复选框

Niv*_*vin 1 sapui5

XML

<columns>
    <Column width="3em">
    <CheckBox select="selectAll"/>
</Column>
<items/>
Run Code Online (Sandbox Code Playgroud)

JS

var table = this.getView().byId("Table");
table.bindItems({
    path: "/",
    template: new sap.m.ColumnListItem({
        cells: [
            new sap.m.CheckBox({
                name: "{ue_connection_name}",
                selected: "{enabled}",
                enabled: true
            }),

        ]
    })
});

selectAll: function() {
 this.selected = true;
}
Run Code Online (Sandbox Code Playgroud)

这里我有几个复选框列表。当我单击表标题中的主复选框时,我想选择所有其他复选框。sapUI5中如何选中所有复选框

Rah*_*waj 5

请尝试以下代码:

我提到评论是为了更好地解释。

selectAll: function(oEvent) {
        var otab = this.byId("idTab"); // Fetch the table

        var bSelected = oEvent.getParameter('selected'); // fetch whether user selected/de-selected all

        otab.getItems().forEach(function(item) { // loop over all the items in the table
            var oCheckBoxCell = item.getCells()[0]; //fetch the cell which holds the checkbox for that row.

            oCheckBoxCell.setSelected(bSelected); // Select/de-select each checkbox
        });
    }
Run Code Online (Sandbox Code Playgroud)

如果您需要更多信息,请发表评论。