Search code examples
nativescriptangular2-nativescriptnativescript-angularnativescript-plugin

Sending a payload through the nativescript background-http plugin, one of its properties being an array


Im trying to send a request to a dotnet core api using the nativescript background-http plugin and in the payload one of the properties represents an array. Im trying to send the array like this:

let params = [
                ..........
                ...invitees.map((v,i) => { name: `invitees.${i}.email`, value: v.email }),
                ...invitees.map((v,i) => { name: `invitees.${i}.name`, value: v.email })
            ]

Also tried it like this:

let params = [
                ..........
                ...invitees.map((v) => { name: `invitees.email`, value: v.email }),
                ...invitees.map((v) => { name: `invitees.name`, value: v.email })
            ]

Neither way works when i debug the api to see how it parses the payload. The rest of the properties which is a mix of primitive types, objects and files parse fine. Any idea on what should be the format? The array is of an object with two properties named name and email.


Solution

  • Made it work like this:

    let params = [
                    ..........
                    ...invitees.map((v,i) => { name: `invitees[${i}].email`, value: v.email }),
                    ...invitees.map((v,i) => { name: `invitees[${i}].name`, value: v.email })
                ]