@beisen-phoenix/transfer

| 成员 | 说明 | 类型 | 默认值 | | ----------------- | :-----------------------------------------------------------------------: | :--------------------------------------------: | ---------- | | canDrag | 是否可拖拽 | boolean | false | | titles | 标题集合,顺序从左至右 | string[] | ['', ''] | | showSearch | 是否显示搜索框 | boolean | false | | leastCount | 设置最少选择几条 | number | - | | searchPlaceholder | 搜索框 placeholder 内容 | string | '请搜索' | | notFoundContent | 无数据时展示内容 | string, React.ReactNode | '暂无数据' | | width | 自定义宽度 | string | - | | height | 自定义高度 | string | - | | dataSource | 穿梭框数据(type 在 group 模式下数据结构有些不同,具体见下方 TransferItem) | TransferItem[] | [] | | targetKeys | 显示在右侧数据的 key 集合 | string[] | [] | | selectedKeys | 设置哪些项应该被选中 | string[] | [] | | type | 类型 | string(“group” / "normal") | normal | | lazy | 使用 react-lazy-load 优化性能,可参照 react-lazy-load 设置相关参数 | - | | onChange | 选项在两栏之间转移时的回调函数 | (targetKeys, direction, moveKeys): void | | onSelectChange | 选中项发生改变时的回调函数 | (sourceSelectedKeys, targetSelectedKeys): void | - | | onSearch | 搜索框内容时改变时的回调函数 | (direction: 'left', value: string): void | - | | onScroll | 选项列表滚动时的回调函数 | (direction, event): void | - | | onDragChange | 选项拖拽时的回调函数 | (dataSource, targetkeys): void | - |

Usage no npm install needed!

<script type="module">
  import beisenPhoenixTransfer from 'https://cdn.skypack.dev/@beisen-phoenix/transfer';
</script>

README

穿梭框

API 属性如下:

成员 说明 类型 默认值
canDrag 是否可拖拽 boolean false
titles 标题集合,顺序从左至右 string[] ['', '']
showSearch 是否显示搜索框 boolean false
leastCount 设置最少选择几条 number -
searchPlaceholder 搜索框 placeholder 内容 string '请搜索'
notFoundContent 无数据时展示内容 string, React.ReactNode '暂无数据'
width 自定义宽度 string -
height 自定义高度 string -
dataSource 穿梭框数据(type 在 group 模式下数据结构有些不同,具体见下方 TransferItem) TransferItem[] []
targetKeys 显示在右侧数据的 key 集合 string[] []
selectedKeys 设置哪些项应该被选中 string[] []
type 类型 string(“group” / "normal") normal
lazy 使用 react-lazy-load 优化性能,可参照 react-lazy-load 设置相关参数 -
onChange 选项在两栏之间转移时的回调函数 (targetKeys, direction, moveKeys): void
onSelectChange 选中项发生改变时的回调函数 (sourceSelectedKeys, targetSelectedKeys): void -
onSearch 搜索框内容时改变时的回调函数 (direction: 'left', value: string): void -
onScroll 选项列表滚动时的回调函数 (direction, event): void -
onDragChange 选项拖拽时的回调函数 (dataSource, targetkeys): void -

changelog

2019/10/28 1、新增 type 属性(“group”|“normal”) 2、新增左侧选择支持分组(目前仅支持一级分组) 3、删除 rowKey 属性 4、删除 dataSource 里的 value 属性,key 属性为必填(key 就是 value) 5、type 为 group 的时候,dataSource 的数据结构

注意:

按照 React 的规范,所有的组件数组必须绑定 key。在 Transfer 中,dataSource 里的数据值需要指定 key 值。对于 dataSource 默认将每列数据的 key 属性作为唯一的标识。

如果你的数据没有这个属性,务必使用 rowKey 来指定数据列的主键。

// 比如你的数据主键是 uid
return <Transfer rowKey={record => record.uid} />;

TransferItem 类型

//当type为normal或者不传的时候
const dataSource = [{
    key: ‘12345’,
    title: '测试1',
    disabled: false
}]
//当type为group当时候
const dataSource =[{
    key:"groupKey",
    title:"groupTitle",
    children:[{
        key:"12345",
        title:"名称",
        disabled:false
    }]
}]