【问题标题】:Is it possible to use destructuring to declare in less lines of code this decalarations? [duplicate]是否可以使用解构以更少的代码行来声明这个声明? [复制]
【发布时间】:2023-01-12 06:53:12
【问题描述】:

是否可以使用解构以更少的代码行来声明这个声明?

const identification_type = this.phaseOneForm.controls.identification_type.value;
const identification_number =this.phaseOneForm.controls.identification_number.value;
const date_of_issue = this.phaseOneForm.controls.date_of_issue.value;
const date_of_birth = this.phaseOneForm.controls.date_of_birth.value;
const pep = this.phaseOneForm.controls.pep.value;
const us = this.phaseOneForm.controls.us.value;
const qualified_investor = this.phaseOneForm.controls.qualified_investor.value;

我试过了:

const {
  value: identification_type,
  value: identification_number,
  value: date_of_issue,
  value: date_of_birth,
  value: pep,
  value: us,
  value: qualified_investor,
} = this.phaseOneForm.controls;

但不起作用

【问题讨论】:

  • 你做的一切都是对的,但需要使用这个语法identification_type: {value: identification_type},

标签: javascript arrays object javascript-objects


【解决方案1】:

你的语法不完全正确

const {
    identification_type: {
        value: identification_type
    },
    identification_number : {
        value: identification_number 
    },
    date_of_issue: {
      value: date_of_issue
    },
    date_of_birth : {
        value: date_of_birth 
    },
    pep : {
        value: pep 
    },
    us : {
        value: us 
    },
    qualified_investor : {
        value: qualified_investor 
    }
} = this.phaseOneForm.controls;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    相关资源
    最近更新 更多