如何使用数组索引从现有的嵌套数组中创建新数组

时间:2019-02-12 06:50:39

标签: arrays types nested

下面的代码为我提供了以下格式的数据,我想将所有Array(1)转换为Array(8)。如何在angular2中实现 [Array(8),Array(8),Array(8),Array(1),Array(1),Array(1),Array(1),Array(1),Array(1),Array(1) ,Array(1)]

buildBCVATable(observations) {
    console.log("genericConceptIdentify", observations);
    var data = [];
    data.push(
      [{ text: 'BCVA', style: 'tableHeader', colSpan: 8, alignment: 'center' }, {}, {}, {}, {}, {}, {}, {}],
      [{ text: 'R', style: 'tableHeader', colSpan: 4, alignment: 'center' }, {}, {}, {},
      { text: 'L', style: 'tableHeader', colSpan: 4, alignment: 'center' }, {}, {}, {}],
      [
        { text: 'SPH', style: 'tableHeader', colSpan: 1, alignment: 'center' },
        { text: 'CYL', style: 'tableHeader', colSpan: 1, alignment: 'center' },
        { text: 'AXS', style: 'tableHeader', colSpan: 1, alignment: 'center' },
        { text: 'VA', style: 'tableHeader', colSpan: 1, alignment: 'center' },
        { text: 'SPH', style: 'tableHeader', colSpan: 1, alignment: 'center' },
        { text: 'CYL', style: 'tableHeader', colSpan: 1, alignment: 'center' },
        { text: 'AXS', style: 'tableHeader', colSpan: 1, alignment: 'center' },
        { text: 'VA', style: 'tableHeader', colSpan: 1, alignment: 'center' }],
    );
    //data.push([8,7,6,5,4,3,2,1]);
    let dataValues: any[] = [];
    let dataNames: any[] = [];
    observations.forEach(obs => {
      if (obs.concept.uuid == "41b2dc35-ace0-4fbe-a852-16559482a590") {//SPHR
           //data[2].SPH = obs.value;
           //dataNames.push([{text:obs.concept.display}]);
           console.log("SPH",obs);
           dataValues.push(obs.value);
      }
      if (obs.concept.uuid == "a5fa46ee-f36a-4fce-99d5-0ef73af7977b") {//CYLR
          //data[2].CYL = obs.value;
          //dataNames.push([obs.concept.display]);
          //dataNames.push([{text:obs.concept.display}]);
          dataValues.push(obs.value);
      }
      if (obs.concept.uuid == "67af52ed-9c9c-439c-b92f-6ea871422e70") {//AXSR
          //data[2].AXS = obs.value;
          //dataNames.push([obs.concept.display]);
          //dataNames.push([{text:obs.concept.display}]);
          dataValues.push(obs.value);
      }
      if (obs.concept.uuid == "728bfa47-2798-4701-99e6-5f40dc4f338c") {//VAR
          //data[2].VA = obs.value;
          //dataNames.push([obs.concept.display]);
          //dataNames.push([{text:obs.concept.display}]);
          dataValues.push(obs.value);
      }
      if (obs.concept.uuid == "7d116d0a-5696-45ea-833d-b07c5bcce361") {//SPHL
          //data[2].SPH = obs.value;
          //dataNames.push([obs.concept.display]);
          //dataNames.push([{text:obs.concept.display}]);
          dataValues.push(obs.value);
      }
      if (obs.concept.uuid == "83ebdf32-131b-4506-851e-d9df62f9001f") {//CYLL
            //data[2].CYL = obs.value;
            //dataNames.push([obs.concept.display]);
           //dataNames.push([{text:obs.concept.display}]);
            dataValues.push(obs.value);
      }
      if (obs.concept.uuid == "25c31298-7736-406f-b82b-b8faf3a66868") {//AXSL
            //data[2].AXS = obs.value;
            //dataNames.push([obs.concept.display]);
           dataNames.push([{text:obs.concept.display}]);
            dataValues.push(obs.value);
      }
      if (obs.concept.uuid == "7d5fb7d4-2ba5-43eb-a480-a35f22d59e39") {//VAL
            //data[0].VA = obs.value;
            //dataNames.push([obs.concept.display]);
           dataNames.push([{text:obs.concept.display}]);
            dataValues.push(obs.value);
      }
    });
    console.log("BCVAData", data);
    data.push(dataValues);
    return data;
  }

目前,数据为我提供了以下嵌套数组

[Array(8), Array(8), Array(8), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1), Array(1)]

我希望将所有这些Array(1)合并为Array(8),这将帮助我将动态数据显示到pdfmake库中。谢谢

0 个答案:

没有答案