multiSelectListBox 多选列表
multiSelectListBox 支持用户通过复选框在一个可滚动的列表中选择多个数据。
XML 元素 |
|
|---|---|
Java 类 |
|
基本用法
使用 itemsContainer 或 itemsEnum 创建选项列表:
XML
<vbox width="AUTO">
<h4 text="Single-select ListBox"/>
<listBox id="listBox"/>
</vbox>
<vbox width="AUTO">
<h4 text="Multi-select ListBox"/>
<multiSelectListBox id="multiSelectListBox"/>
</vbox>
Java
@ViewComponent
protected JmixListBox<String> listBox;
@ViewComponent
protected JmixMultiSelectListBox<String> multiSelectListBox;
@Subscribe
protected void onInit(InitEvent event) {
List<String> items = List.of("CSS", "HTML", "Java", "JavaScript", "JSON", "Kotlin", "XML");
listBox.setItems(items);
multiSelectListBox.setItems(items);
listBox.setValue("Java");
multiSelectListBox.select("Java", "Kotlin");
}
选项状态 Provider
itemEnabledProvider 支持按特定条件动态控制单个选项是否启用。禁用的选项显示灰色,无法被用户选中。所有选项默认启用。
@Install(to = "multiSelectListBox", subject = "itemEnabledProvider")
private boolean multiSelectListBoxItemEnabledProvider(final User user) {
if (user != null) {
return user.getActive();
}
return true;
}
自定义选项标签
itemLabelGenerator 支持自定义选项在 multiSelectListBox 组件中的显示标签。可以控制用户看到的文本,能以更友好的方式或上下文更相关的方式展示选项。
@Install(to = "multiSelectListBox", subject = "itemLabelGenerator")
private String multiSelectListBoxItemLabelGenerator(final User item) {
return metadataTools.format(item.getDisplayName()).toUpperCase();
}
选项渲染
可以自定义选项的渲染方式。渲染器在每个选项应用,返回一个表示该选项的组件。
可以使用 setRenderer() 方法或 @Supply 注解实现。
@Supply(to = "mSelectListBox", subject = "renderer")
private ComponentRenderer<Span, User> mSelectListBoxRenderer() {
return new ComponentRenderer<>(user -> {
Span span = uiComponents.create(Span.class);
span.setText(user.getDisplayName());
span.setClassName("font-bold");
return span;
});
}
或者,还可以使用嵌套的 fragmentRenderer 元素来渲染选项。更多信息请参考 Fragment 渲染器 部分。
事件和处理器
下面是 multiSelectListBox 的特殊处理方法:
| 名称 | 描述 |
|---|---|
|
|
支持自定义 |
|
为 |
下面是 multiSelectListBox 支持的其他通用事件:
XML 内部元素
一个 multiSelectListBox 可以包含 fragmentRenderer 和 tooltip 作为其内部元素。
本页是否有帮助?
感谢您的反馈