小编And*_*yer的帖子

复制没有某些字段的状态对象

我需要将组件的状态转移到其父组件,但我不需要传输所有字段.

我目前在做什么:

submitHandler = (e) => {
    e.preventDefault();
    const newState = Object.keys(this.state).map(item => {
        if(item !== 'errors')
        {
            return { item: this.state[item] }
        }
    });

    console.log(newState);
    this.props.onChange(newState);
}
Run Code Online (Sandbox Code Playgroud)

显然这不是我需要的.

state = {
    errors: {
        fio: '',
        email: '',
        phone: ''
    },
    owner: owner.Company,
    fio: null,
    company: null,
    phone: null,
    fax: null,
    email: null,
    adress: null
}
Run Code Online (Sandbox Code Playgroud)

我需要转移除了以外的所有字段errors.我怎样才能做到这一点?

javascript ecmascript-6 reactjs

2
推荐指数
1
解决办法
47
查看次数

标签 统计

ecmascript-6 ×1

javascript ×1

reactjs ×1