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**
}
语句
包含
{
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屋!
查看全文