Transfer穿梭框

表单控件。

何时使用

代码演示

Transfer 穿梭框 - 图1

基本使用

基本使用。

  1. import { Transfer, Switch } from 'choerodon-ui/pro';
  2. function handleChange(value, oldValue) {
  3. console.log('[basic new]', value, '[basic old]', oldValue);
  4. }
  5. const { Option } = Transfer;
  6. class App extends React.Component {
  7. state = { disabled: false };
  8. handleDisableChange = value => this.setState({ disabled: value });
  9. render() {
  10. return (
  11. <div>
  12. <Switch onChange={this.handleDisableChange}>disabled</Switch>
  13. <br />
  14. <Transfer onChange={handleChange} disabled={this.state.disabled} titles={['Source', 'Target']}>
  15. <Option value="jack">Jack</Option>
  16. <Option value="lucy">Lucy</Option>
  17. <Option value="wu">Wu</Option>
  18. </Transfer>
  19. </div>
  20. );
  21. }
  22. }
  23. ReactDOM.render(
  24. <App />,
  25. mountNode
  26. );

Transfer 穿梭框 - 图2

绑定数据源

绑定数据源。

  1. import { DataSet, Transfer, Row, Col } from 'choerodon-ui/pro';
  2. function handleDataSetChange({ record, name, value, oldValue }) {
  3. console.log('[dataset newValue]', value, '[oldValue]', oldValue, '[record.get(name)]', record.get(name));
  4. }
  5. const { Option } = Transfer;
  6. const optionData = [
  7. { text: 'Jack', value: 'jack' },
  8. { text: 'Huazhen', value: 'huazhen' },
  9. { text: 'Lucy', value: 'lucy' },
  10. { text: 'Niu', value: 'jiaqin' },
  11. { text: 'Shao', value: 'shao' },
  12. ];
  13. const data = [{
  14. 'first-name': 'huazhen',
  15. 'last-name': 'wu',
  16. }];
  17. class App extends React.Component {
  18. optionDs = new DataSet({
  19. data: optionData,
  20. selection: 'single',
  21. });
  22. ds = new DataSet({
  23. data,
  24. fields: [
  25. { name: 'first-name', type: 'string', label: '名', textField: 'text', valueField: 'value', options: this.optionDs },
  26. { name: 'last-name', type: 'string', label: '姓' },
  27. ],
  28. events: {
  29. update: handleDataSetChange,
  30. },
  31. });
  32. render() {
  33. return (
  34. <div>
  35. <Transfer dataSet={this.ds} name="first-name" />
  36. <Transfer dataSet={this.ds} name="last-name">
  37. <Option value="jack">Jack</Option>
  38. <Option value="lucy">Lucy</Option>
  39. <Option value="wu">Wu</Option>
  40. </Transfer>
  41. </div>
  42. );
  43. }
  44. }
  45. ReactDOM.render(
  46. <App />,
  47. mountNode
  48. );

Transfer 穿梭框 - 图3

可搜索

可搜索。

  1. import { DataSet, Transfer } from 'choerodon-ui/pro';
  2. function handleDataSetChange({ record, name, value, oldValue }) {
  3. console.log('[searchable]', value, '[oldValue]', oldValue, `[record.get('${name}')]`, record.get(name));
  4. }
  5. const { Option } = Transfer;
  6. const data = [{
  7. 'last-name': 'huazhen',
  8. }];
  9. class App extends React.Component {
  10. ds = new DataSet({
  11. data,
  12. fields: [
  13. { name: 'last-name', type: 'string', label: '姓' },
  14. ],
  15. events: {
  16. update: handleDataSetChange,
  17. },
  18. });
  19. render() {
  20. return (
  21. <Transfer dataSet={this.ds} name="last-name" searchable>
  22. <Option value="jack">Jack</Option>
  23. <Option value="lucy">Lucy</Option>
  24. <Option value="huazhen">Huazhen</Option>
  25. </Transfer>
  26. );
  27. }
  28. }
  29. ReactDOM.render(
  30. <App />,
  31. mountNode
  32. );

Transfer 穿梭框 - 图4

受控穿梭框

受控穿梭框。

  1. import { Transfer } from 'choerodon-ui/pro';
  2. const { Option } = Transfer;
  3. class App extends React.Component {
  4. constructor(props) {
  5. super(props);
  6. this.state = {
  7. value: 'wu',
  8. };
  9. }
  10. handleChange = (value, oldValue) => {
  11. console.log('[constrolled]', 'newValue', value, '[oldValue]', oldValue);
  12. this.setState({
  13. value,
  14. });
  15. }
  16. render() {
  17. return (
  18. <Transfer value={this.state.value} onChange={this.handleChange}>
  19. <Option value="jack">Jack</Option>
  20. <Option value="lucy">Lucy</Option>
  21. <Option value="wu">Wu</Option>
  22. </Transfer>
  23. );
  24. }
  25. }
  26. ReactDOM.render(
  27. <App />,
  28. mountNode
  29. );

Transfer 穿梭框 - 图5

值列表代码

值列表代码。

  1. import { DataSet, Transfer, Button, Row, Col } from 'choerodon-ui/pro';
  2. function handleDataSetChange({ record, name, value, oldValue }) {
  3. console.log('[dataset newValue]', value, '[oldValue]', oldValue, `[record.get('${name}')]`, record.get(name));
  4. }
  5. class App extends React.Component {
  6. flag = false;
  7. ds = new DataSet({
  8. autoCreate: true,
  9. fields: [
  10. { name: 'sex', type: 'string', lookupCode: 'HR.EMPLOYEE_GENDER', defaultValue: 'F' },
  11. { name: 'sex2', type: 'string', lookupUrl: '/common/code/HR.EMPLOYEE_GENDER/' },
  12. { name: 'lov', type: 'string', lovCode: 'LOV_CODE', defaultValue: 'SYS.PROFILE_LEVEL_ID' },
  13. { name: 'lov2', type: 'string', lovCode: 'LOV_CODE', defaultValue: ['SYS.PROFILE_LEVEL_ID', 'SYS.RESOURCE_TYPE'], multiple: true },
  14. ],
  15. events: {
  16. update: handleDataSetChange,
  17. },
  18. });
  19. changeLookupCode = () => {
  20. this.flag = !this.flag;
  21. this.ds.getField('sex').set('lookupCode', this.flag ? 'SYS.USER_STATUS' : 'HR.EMPLOYEE_GENDER');
  22. };
  23. render() {
  24. return (
  25. <Row gutter={10}>
  26. <Col span={18}>
  27. <Transfer dataSet={this.ds} name="sex" placeholder="请选择" />
  28. </Col>
  29. <Col span={6}>
  30. <Button onClick={this.changeLookupCode}>修改lookupCode</Button>
  31. </Col>
  32. <Col span={24}>
  33. <Transfer dataSet={this.ds} name="sex2" placeholder="请选择" />
  34. </Col>
  35. <Col span={24}>
  36. <Transfer dataSet={this.ds} name="lov" placeholder="请选择" />
  37. </Col>
  38. <Col span={24}>
  39. <Transfer dataSet={this.ds} name="lov2" placeholder="请选择" />
  40. </Col>
  41. </Row>
  42. );
  43. }
  44. }
  45. ReactDOM.render(
  46. <App />,
  47. mountNode
  48. );

Transfer 穿梭框 - 图6

单选

单选。

  1. import { Transfer, Switch } from 'choerodon-ui/pro';
  2. function handleChange(value, oldValue) {
  3. console.log('[basic new]', value, '[basic old]', oldValue);
  4. }
  5. const { Option } = Transfer;
  6. ReactDOM.render(
  7. <Transfer multiple={false} onChange={handleChange}>
  8. <Option value="jack">Jack</Option>
  9. <Option value="lucy">Lucy</Option>
  10. <Option value="wu">Wu</Option>
  11. </Transfer>,
  12. mountNode
  13. );

API

Transfer

参数说明类型默认值

更多属性请参考 Select

Transfer.OptGroup

参数说明类型默认值
label选项组标题string

Transfer.Option

参数说明类型默认值
value选项值any