0

我需要使用 . 单击选择/取消选择所有复选框CardService

如何实现onclick处理函数?

我尝试过:

function handlerOfButtonClick(e) {
    var selectAll = CardService.newSelectionInput()
        .setType(CardService.SelectionInputType.CHECK_BOX)
        .setFieldName("select_all")
        .addItem("Select all", "selectAll", false).setOnChangeAction(CardService.newAction()
            .setFunctionName("handleSelectAll"));

    var checkboxGroup = CardService.newSelectionInput()
        .setType(CardService.SelectionInputType.CHECK_BOX)
        .setTitle("A group of checkboxes. Multiple selections are allowed.")
        .setFieldName("checkbox_field")
        .addItem("checkbox one title", "checkbox_one_value", false)
        .addItem("checkbox two title", "checkbox_two_value", true)
        .addItem("checkbox three title", "checkbox_three_value", true);

    var section = CardService.newCardSection().addWidget(selectAll).addWidget(checkboxGroup)
    var card = CardService.newCardBuilder().addSection(section);
    var navigation = CardService.newNavigation().pushCard(card.build());
    var actionResponse = CardService.newActionResponseBuilder().setNavigation(navigation);
    return actionResponse.build();
}

function handleSelectAll(e) {
    //????? 
}
4

1 回答 1

2

您可以使用方法updateCard(card)

这允许您将您构建的卡替换为选中所有复选框的版本(即 se to true)。

样本:

function handleSelectAll(e) {
    
    var checkboxGroup = CardService.newSelectionInput()
        .setType(CardService.SelectionInputType.CHECK_BOX)
        .setTitle("A group of checkboxes. Multiple selections are allowed.")
        .setFieldName("checkbox_field")
        .addItem("checkbox one title", "checkbox_one_value", true)
        .addItem("checkbox two title", "checkbox_two_value", true)
        .addItem("checkbox three title", "checkbox_three_value", true);

    var section = CardService.newCardSection().addWidget(selectAll).addWidget(checkboxGroup)
    var card = CardService.newCardBuilder().addSection(section);

    return CardService.newNavigation().updateCard(card.build());
}
于 2020-10-26T11:48:48.990 回答