I am planning to send array data using formData. The backend is set up to accept the data array separated by a dash ; For example, if I were to use Postman and input the form-data like this:
id_barang : 122;288;383 (sending 3 values of id with dashes ;)
Would my formData implementation look something like this?
data [
{
id_barang : 122
},
{
id_barang : 288
},
{
id_barang : 383
}
]
let barang = data.map(x => x.id_barang).join(";");
const f = new FormData();
f.append("id_barang", barang);
//If there are any mistakes in my approach, please do correct me
This is how my backend processes the data:
id_barang_data := strings.Split(r.FormValue("id_barang"), ";") // This will result in: 1002;983;756
for i, _ := range id_barang_data { // Looping through each value one by one
rSegAnalisaMethodDetail := models.SegAnalisaMethodDetail{}
id_barang, err := strconv.Atoi(id_barang_data[i])
if err != nil {
responses.ERROR(w, http.StatusBadGateway, err)
}