微信小程序循环请求api


这里调用循环请求api
that.allTypeApi(that.data.allType,0);



//多个请求。
allTypeApi:function (data,i){
var that= this

//api请求开始
console.log('打印一下:')
console.log(i)
console.log(data[i])
console.log(data.length)
wx.request({
url: 'https://网址,请求的网址',
data: {
openId: wx.getStorageSync('openId'),
requestType: "queryCondition",
requestCondition: 'wx_id',
conditionValue: data[i]
},
success: function (response) {
if (response.statusCode == '200') {
var count = response.data.indexOf("\r\n\r\n<!DOC");
var str = response.data.substring(0, count)
var json = JSON.parse(utils.encrypt(str))
if (json.length < 1) {
that.setData({
})
} else {
console.log("商品信息json:")
console.log(json)
console.log(json[0].Title)
console.log(json[0].TypeName)
//参数
var tempParam = that.data.paramList

console.log(that.data.paramList)
var eachParam = {
"id": json[0].Wx_id,
"goodType": json[0].TypeName,
"goodTitle": json[0].Title,
"goodPrice": json[0].Price,
"rel_bust": 0,
"middleWaist": 0,
"shoulderWidth": 0,
"frontLength": 0,
"sleeve": 0,
"waist": 0,
"hipline": 0,
"acrossPants": 0,
"trouserL": 0,
"feet": 0,
"neck": 0
}
tempParam.push(eachParam)

//标题选项卡
var tempNavbar = that.data.navbar//选项卡标题
tempNavbar.push(json[0].TypeName)
that.setData({
navbar: tempNavbar,
paramList: tempParam
})
console.log('for循环打印开始了:')
console.log(that.data.paramList)
}
}
},
fail: function (resFail) {
console.log(resFail)

},
complete: function (resComp) {
if ((i + 1) >= data.length) {
console.log('执行完毕了。')
} else {
that.allTypeApi(that.data.allType, i + 1);
}
},
})
//api请求结束
},
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值