简体   繁体   中英

How to send Object data to Api in react native

this is the data i want to send to api

"postcodes": { "postcode_0": { "postcode_id": "postcode-0001" }, "postcode_1": { "postcode_id": "postcode-0002" } },

this is my code

const responsepostal = await axios.post
                (`${urldemo}postal-codes`)
            setData3(responsepostal.data.result)

const [data3, setData3] = useState([])
    const [postcodes, setPostcodess] = useState([]);


 var dataToSend = {
                postcodes: postcodes,
            };

 <Picker style={GlobalSS.picker}
                        // selectedValue={postcodes.toString()}
                        selectedValue={postcodes}
                        mode='dropdown'
                        dropdownIconRippleColor='orange'
                        dropdownIconColor='#FF8025'
                        onValueChange={(itemValue, itemIndex) =>
                            setPostcodess(itemValue)
                        }>

                        <Picker.Item color='grey'
                            label="Select Postal Code " value="" />
                        {data3.map(item => (
                            <Picker.Item label={item.text} value={item.id} />
                        ))}
                    </Picker>

for Sending the data in Object

let's create an empty Object

then assign data to object then send data to API by params

  1. let objData = {}

  2. objData = postcodes

  3. Send this objData to api

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM