ES6深层嵌套对象分解 [英] ES6 deep nested object destructuring
本文介绍了ES6深层嵌套对象分解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为this.props
的对象,其中包含
I have an object called this.props
which contains
{
actions: Object,
dirty: false,
form: "Statement",
autofill: functon(),
**statement: Object**
}
statement
包含
{
firstName: "John"
lastName: "Peter"
isConfirmed: true
}
我想使用es6解构在同一行中提取statement
对象和isConfirmed
属性
I would like to extract statement
object and the isConfirmed
property in the same line using es6 destructuring
我尝试过
const { statement: isConfirmed, isAdmin } = this.props
当我执行let a = isConfirmed, b = statement
推荐答案
我想在同一行中提取语句对象和isConfirmed属性
I would like to extract statement object and the isConfirmed property in the same line
const { statement: { isConfirmed }, statement } = this.props;
这样,您可以同时获取isConfirmed
和整个statement
对象.
That way you get both isConfirmed
and the whole statement
object.
参考文献:
这篇关于ES6深层嵌套对象分解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文