美文网首页
处理form表单提交参数未知时,对时间类型参数进行处理

处理form表单提交参数未知时,对时间类型参数进行处理

作者: 华戈的小书 | 来源:发表于2019-10-11 15:37 被阅读0次

使用lodash插件

使用到的方法:

  • pickBy 筛选出对象中符合条件的属性,返回一个对象;
  • forOwn 遍历一个对象;
  • isUndefined 值类型为undefined,返回值为true;
  • isObject 值类型为Object,返回值为true;

示例:

import { isUndefined, isObject, pickBy, forOwn } from 'lodash';
import { moment } from 'moment';

const dateTime = 'YY-MM-DD';

const { form } = this.props;
const formValues = isUndefined(form) ? {} : form.getFieldsValue(); // 未处理的form表单
// 开始处理日期格式数据
const dateFormFields = pickBy(formValues, isObject);
let newDateFormFields = {};
forOwn(dateFormFields, (vlaue, key) => {
    newDateFormFields = Object.assign({}, newDateFormFields, { [key]: moment(value).format(dateTime) });
})

const newFormValues = { ...formValues, ...newDateFormFields }; // 处理后的form表单

相关文章

网友评论

      本文标题:处理form表单提交参数未知时,对时间类型参数进行处理

      本文链接:https://www.haomeiwen.com/subject/inztmctx.html