【问题标题】:How to set each element to a (value, label) in a array [closed]如何将每个元素设置为数组中的(值,标签)[关闭]
【发布时间】:2022-06-15 20:03:04
【问题描述】:

我怎样才能得到我在打印屏幕上涂成红色的每个 element.value 的返回值,forEach 循环只是重复映射(元素),有人可以解释这是如何工作的吗? 我的 childData:{“COMPANY 1, COMPANY2, COMPANY3...},我正在尝试映射他返回

[0]: {value: company1, label: company1}
[1]: {value: company2, label: company2}
public getCNPJ(childData?){
    const db = this.db.database;  
    const ref = db.ref('parceiro')
    var cnpjs = []
    var refs = db.ref('parceiro').once('value').then(function(snap){
      snap.forEach(function(childSnap){
        var key = childSnap.key
        var childData =  childSnap.val().cadastro.razao_social
        console.log(childData)
        cnpjs.push(childData)
      })
   
    }).then(()=>{
      cnpjs.forEach(idx => {
        cnpjs.map((element, i) =>{
          return this.pj = [{
            value: element,
            label: element
          }]
        })      
        console.log('this.pj', this.pj)
        childData = this.pj
        this.empresa_option = this.pj
        console.log(this.empresa_option)
        return childData
      });
    })
  }

Printscreen of Console.LOG to help the understanding

【问题讨论】:

  • 您的起始数据是什么,您希望从该数据中获得什么精确/准确的输出?
  • @DavidThomas 我的起始数据位于图像中的红色方块上,即公司名称。输出需要类似于 [0]:{ value: company.name, label: company.name},所有公司都在红色方块上

标签: javascript arrays angular typescript firebase


猜你喜欢
  • 2012-07-11
  • 1970-01-01
  • 2021-04-12
  • 2021-11-09
  • 2021-08-05
  • 2021-09-08
  • 1970-01-01
  • 1970-01-01
  • 2021-09-04
相关资源
最近更新 更多