直接跳到内容

SelectionList / Selection 多选列表

SelectionList 是支持多选的列表组件,Selection 是其子选项组件。用户可以通过空格键切换每项的选中状态,适用于多项选择的表单场景。

底层:Textual SelectionList

基本用法

SelectionList Props

SelectionList 无特殊 Props,通过子 Selection 组件声明选项。

Selection Props

属性类型默认值说明
promptstr必填,选项显示文字
valueanyprompt 相同选项的绑定值,选中后通过 .selected 返回此值
initial_stateboolFalse初始是否处于选中状态

v-model

  • SelectionListv-model,通过 ref 访问 .selected 获取选中值列表
  • Selectionv-model 默认绑定属性:prompt

事件

事件说明
selection_list_selected_changed选中项列表发生变化时触发(对应 Textual SelectionList.SelectedChanged

通过 ref 访问

通过 ref 获取 SelectionList 实例后,可访问:

属性 / 方法说明
.selected当前所有选中项的 value 列表
.clear_selections()清除所有选中状态
.select_all()选中所有选项

通用属性

所有 Textual-vuepy 组件均支持以下属性:

属性类型说明
idstr组件 CSS ID
stylestrTCSS 内联样式
classstrTCSS 类名(空格分隔)
border_titlestr边框标题
border_subtitlestr边框副标题
SelectionList / Selection 多选列表已经加载完毕