所以我使用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')'。你还想要什么? –