在循环请求后,不支持es6语法,也不传给服务器json格式,接口只会返回成功状态,没有任何的标识,在前端怎么知道当前传递成功的是哪个数组元素。谢谢var arr = [{ gymAddr: "00000000", trainingActionId: "123", deviceId: "1"}, { gymAddr: "00000000", trainingActionId: "123", deviceId: "2"}, { gymAddr: "00000000", trainingActionId: "123", deviceId: "3"}]for (var i = 0; i < arr.length; i++) {
wx.request({ url: "https://localhost:8080/trainingRecord/single", data: arr[i], method: 'POST', header: { 'content-type': 'application/x-www-form-urlencoded'
}, success: function(res) { console.log('res', res); console.log(this)
}
})
}
1 回答
杨__羊羊
TA贡献1943条经验 获得超7个赞
for (let i = 0; i < arr.length; i++) { // 注意这一行 request({ url: "https://localhost:8080/trainingRecord/single", data: arr[i], method: 'POST', header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function(res) { console.log('res', res, i); console.log(this) } }) }
或者:
for (var i = 0; i < arr.length; i++) { // 注意下面这一行 (function(i){ request({ url: "https://localhost:8080/trainingRecord/single", data: arr[i], method: 'POST', header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function(res) { console.log('res', res, i); console.log(this) } }) })(i) }
添加回答
举报
0/150
提交
取消