React TSX 从一组二维数据中,重新挑选数组组成新数组示例:

源数据

[
    {
        "value": "6",
        "label": "Markus",
        "avatar": "http://127.0.0.1/images/avatar/7228462491.png",
        "role": "",
        "email": "[email protected]",
        "id_user": "6",
        "permisson_role_title": "程序员",
        "id_permission_role": 47
    },
    {
        "value": "7",
        "label": "DaZeng",
        "avatar": "http://127.0.0.1/images/avatar/4898025611.png",
        "role": "",
        "email": "[email protected]",
        "id_user": "7",
        "permisson_role_title": "程序员",
        "id_permission_role": 47
    }
]

新数据

// Using new fields to assemble new data and adding it to form 
const callBackAddUserToTaskFunction = (value: any) => {
  if (Array.isArray(value)) {
    const employees = value.map((item: any) => ({
      "user_role_id": item.id_permission_role,
      "user_id": item.id_user,
    }));
    form.setFieldValue('employees', employees as []);
  }
}
[
    {
      "user_role_id": 46,
      "user_id": "5"
    },
    {
      "user_role_id": 46,
      "user_id": "6"
    }
  ]

你可能感兴趣的:(react.js,javascript,前端)