0

需要关于.selectall 功能的帮助。我创建了一个表格。

DynamicForm form = new DynamicForm();  
final SelectItem category = new SelectItem("category", "Employee Category");  
category.setMultiple(true);  
category.setValueMap("Direct","InDirect","ALL");  
form.setFields(category);  

如果我选择“所有”选项列表中的所有三个项目也应该被选中。如果我取消选择“所有”所有三个项目都应该被删除。需要帮忙

4

1 回答 1

3

您可以尝试以下方法:

boolean isAllSelected = false; // global variable
SelectItem selectItem = new SelectItem("category", "Employee Category");
selectItem.setMultiple(true);
selectItem.setMultipleAppearance(MultipleAppearance.PICKLIST);
selectItem.setValueMap("Direct","InDirect","ALL");
selectItem.addChangedHandler(new ChangedHandler() {

    @Override
    public void onChanged(ChangedEvent event) {
        if (event.getValue() != null) {
            if (event.getValue().toString().contains("ALL")) {
                if (!isAllSelected) {
                    selectItem.setValues("Direct","InDirect", "ALL");
                    isAllSelected = true;
                }
            } else {
                if (isAllSelected) {
                    selectItem.clearValue();
                }
                isAllSelected = false;
            }
        } else {
            isAllSelected = false;
        }
    }
});

DynamicForm form = new DynamicForm();
form.setSize("800px", "400px");
form.setFields(selectItem);
form.draw();
于 2013-11-08T06:10:18.303 回答