将对象中的数据根据key映射到数组对象中

data对象值如下

{
        "tp_out": "",
        "code": "20180202SC0NW 0052",
        "tn_out": "",
        "tn_standar": "15",
        "cod_out": "",
        "nh_out": "",
        "nh_in": "",
        "tp_standar": "0.5",
        "nh_standar": "5",
        "cod_in": "",
        "name": "镇生活污水处理设施",
        "tn_in": "",
        "cod_standar": "50",
        "tp_in": ""
    }

数组如下

  townNumList: [
        {
          name: "COD",
          list: [
            { props: "cod_in", value: "", label: "进水值" },
            { props: "cod_out", value: "", label: "出水值" },
            { props: "cod_standar", value: "", label: "设计值" },
          ],
        },
        {
          name: "TP",
          list: [
            { props: "tp_in", value: "", label: "进水值" },
            { props: "tp_out", value: "", label: "出水值" },
            { props: "tp_standar", value: "", label: "设计值" },
          ],
        },
        {
          name: "TN",
          list: [
            { props: "tn_in", value: "", label: "进水值" },
            { props: "tn_out", value: "", label: "出水值" },
            { props: "tn_standar", value: "", label: "设计值" },
          ],
        },
        {
          name: "NH3-N",
          list: [
            { props: "nh_in", value: "", label: "进水值" },
            { props: "nh_out", value: "", label: "出水值" },
            { props: "nh_standar", value: "", label: "设计值" },
          ],
        },
      ]

根据对象中的key和value把值映射过来

 this.townNumList = this.townNumList.map((item) => {
              const { list, name } = item;

              const newList = list.map((ls) => {
                return { ...ls, value: data[ls.props] };
              });

              return { name, list: newList };
            });

你可能感兴趣的:(js,windows)