您好,登錄后才能下訂單哦!
Ant Design的Transfer組件是一個用于在兩個容器之間進行數(shù)據(jù)傳輸?shù)慕M件,可以在兩個列表之間進行數(shù)據(jù)的移動和篩選。以下是使用Ant Design的Transfer組件的基本步驟:
import { Transfer } from 'antd';
import 'antd/dist/antd.css';
<Transfer
dataSource={dataSource} // 數(shù)據(jù)源,格式為[{ key: '1', title: '標(biāo)題1' }]
showSearch
targetKeys={targetKeys} // 目標(biāo)列表的key值數(shù)組
onChange={handleChange} // 數(shù)據(jù)移動時的回調(diào)函數(shù)
render={item => item.title} // 自定義渲染列表項的方法
/>
const dataSource = [
{ key: '1', title: '標(biāo)題1' },
{ key: '2', title: '標(biāo)題2' },
{ key: '3', title: '標(biāo)題3' },
];
const targetKeys = ['1']; // 初始目標(biāo)列表的key值數(shù)組
const handleChange = (nextTargetKeys, direction, moveKeys) => {
console.log('targetKeys:', nextTargetKeys);
console.log('direction:', direction);
console.log('moveKeys:', moveKeys);
// 更新目標(biāo)列表的key值數(shù)組
setTargetKeys(nextTargetKeys);
};
import React, { useState } from 'react';
import { Transfer } from 'antd';
import 'antd/dist/antd.css';
const Demo = () => {
const [targetKeys, setTargetKeys] = useState(['1']);
const dataSource = [
{ key: '1', title: '標(biāo)題1' },
{ key: '2', title: '標(biāo)題2' },
{ key: '3', title: '標(biāo)題3' },
];
const handleChange = (nextTargetKeys, direction, moveKeys) => {
console.log('targetKeys:', nextTargetKeys);
console.log('direction:', direction);
console.log('moveKeys:', moveKeys);
setTargetKeys(nextTargetKeys);
};
return (
<Transfer
dataSource={dataSource}
showSearch
targetKeys={targetKeys}
onChange={handleChange}
render={item => item.title}
/>
);
};
export default Demo;
通過以上步驟,您可以成功地使用Ant Design的Transfer組件實現(xiàn)數(shù)據(jù)的移動和篩選功能。您也可以根據(jù)需要自定義樣式和邏輯來滿足特定的需求。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。