NativeScript / nativescript-background-http

Background Upload plugin for the NativeScript framework
Apache License 2.0
102 stars 50 forks source link

Sending an array through the payload #207

Closed joey0xx closed 5 years ago

joey0xx commented 5 years ago

Im trying to send a request to a dotnet core api 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.

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

kfw9257 commented 5 years ago

Any update this feature being added? I'm looking to do something similar.

joey0xx commented 5 years ago

Was able to make 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 })
            ]

Notice this part:

{ name: `invitees[${i}].email`, value: v.email })
joey0xx commented 5 years ago

I havent done it with an array of strings but i guess it would be like this

const anArray: string[] = ['string1', 'string2'];
let params = [
                ..........
                ...anArray.map((str, i) => { name: `nameofstringarray[${i}]`, value: str }),
                ...anArray.map((str, i) => { name: `nameofstringarray[${i}]`, value: str })
            ]

Where are you getting the error?