And*_*yer 2 javascript ecmascript-6 reactjs
我需要将组件的状态转移到其父组件,但我不需要传输所有字段.
我目前在做什么:
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.我怎样才能做到这一点?
您可以使用rest运算符来使其工作:)
const { errors, ...newState } = this.state;
this.props.onChange(newState);
Run Code Online (Sandbox Code Playgroud)
我在这里举了一个例子:) https://repl.it/@EQuimper/PleasantTrimDeclarations
| 归档时间: |
|
| 查看次数: |
47 次 |
| 最近记录: |