react我前端处理excal表格数据之后发给后端,但是发过去的表格数据里有很多空括号
如图
然后我发现原因在于我处理完的数据,excal表格中的下拉框出现在数据里了,如图
现在要怎么样去除最后的空括号?
代码如下
读取excal
export default ({ setList, disabled }) => {
function beforeUpload(file) {
if (typeof file.name === 'string' && file.name.indexOf('xlsx') > -1) {
read(file);
} else {
message.error('请上传xlsx文件,建议下载模板');
}
return false;
}
// 读文件
function read(file) {
const reader = new FileReader();
reader.onload = e => {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, {
type: 'array'
});
const firstSheetName = workbook.SheetNames[0];
const sheet = workbook.Sheets[firstSheetName];
const res = XLSX.utils.sheet_to_json(sheet);
console.log('json: ', res);
setList(res);
}
reader.readAsArrayBuffer(file);
}
return (
<Upload
beforeUpload={beforeUpload}
showUploadList={false}
>
<Button type='primary' disabled={disabled} size='small'>导入</Button>
</Upload>
)
}
数据处理如下
useEffect(() => {
if (addDataList.length > 0) {
const newList = []
addDataList.forEach(item => {
let text = item['污染物类型'];
if (text === '船舶垃圾') text = '0';
if (text === '生活污水') text = '1';
if (text === '含油污水') text = '2';
let text2 = item['作业方式'];
if (text2 === '垃圾自转运至处置') text2 = '0';
if (text2 === '污水经管道运输至处置设备') text2 = '1';
if (text2 === '补录接收') text2 = '2';
if (text2 === '智能设备接收') text2 = '3';
if (text2 === '扫车船码接收') text2 = '4';
if (text2 === '扫码设备接收') text2 = '5';
if (text2 === '预约接收') text2 = '6';
if (text2 === '上岸即处理') text2 = '7';
let text3 = item['转运状态'];
if (text3 === '已转运') text3 = '0';
if (text3 === '未转运') text3 = '1';
if (text3 === '待受理') text3 = '2';
if (text3 === '待确认') text3 = '4';
newList.push({
receiveNumbers: item['单号'],
shipName: item['船名'],
type: text,
quantity: item['数量'],
receiveCompany: item['接收单位'],
taskCompany: item['作业单位'],
taskTime: item['接收开始时间'],
taskMode: text2,
state: text3
})
})
updateDetails({
data: {
status: '1',
list: [...newList],
}
}).then(res => {
if (res.code === '0') {
}
})
}
}, [addDataList]);