所以我使用https://github.com/request/request#forms的請求。在tsx文件中,我通過了 id: id, text: string, array: number[]
。如何在反應請求中發佈帶有數組字段的數據?
post(
{json: true, url: '...', form: {id: id, text: text, array: array}},
(error, response, body) => {
if (response.statusCode === 400) {
dispatch(errStep(body['text']));
} else {
dispatch(addStep(body));
}
}
)
這是一個後體法{id: id, text: text, array: array}
。但是,從Django打印request.data
時,我收到<QueryDict: {'text': ['hello'], 'id': ['12'], 'array[0]': ['51'], 'array[1]': ['52']}>
。 這樣,我無法通過調用request.data.getlist('array')
來檢索數組['51','52]。
我希望我的request.data使用以下格式:<QueryDict: {'text': ['hello'], 'id': ['12'], 'array': ['51', '52']}>
,因爲通過調用request.data.getlist('array')
返回[51,52]。
謝謝!
您已明確提到的GetList( '陣列')給出[51,52]。這不是你想要的嗎? –
@RajaSimon請求數據不在[51,53]中,而是在[51]和[53]中分開。 –
但是對於你的請求「我怎麼檢索數組」的答案是'getlist('array')'。你還想要什麼? –