简体   繁体   English

ES6深层嵌套对象解构

[英]ES6 deep nested object destructuring

I have an object called this.props which contains 我有一个名为this.props的对象,其中包含

{
 actions: Object,
 dirty: false,
 form: "Statement",
 autofill: functon(),
 **statement: Object**
}

statement contains statement包含

{
 firstName: "John"
 lastName: "Peter"
 isConfirmed: true
}

I would like to extract statement object and the isConfirmed property in the same line using es6 destructuring 我想使用es6解构在同一行中提取statement对象和isConfirmed属性

I've tried 我试过了

const { statement: isConfirmed, isAdmin } = this.props

which I get an error when I do let a = isConfirmed, b = statement 当我let a = isConfirmed, b = statement时,我得到一个错误

I would like to extract statement object and the isConfirmed property in the same line 我想在同一行中提取语句对象和isConfirmed属性

const { statement: { isConfirmed }, statement } = this.props;

That way you get both isConfirmed and the whole statement object. 这样你就得到了isConfirmed和整个statement对象。

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM