如何使用 CardService 实现点击处理程序?
How to implement a click handler with CardService?
我需要使用 CardService
单击 select/deselect 所有复选框。
如何实现 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) {
//?????
}
你可以使用方法updateCard(card)
这允许您用选中所有复选框的版本替换您构建的卡(即 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());
}
我需要使用 CardService
单击 select/deselect 所有复选框。
如何实现 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) {
//?????
}
你可以使用方法updateCard(card)
这允许您用选中所有复选框的版本替换您构建的卡(即 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());
}