热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

微信小程序循环请求api

这里调用循环请求apithat.allTypeApi(that.data.allType,0);多个请求。allTypeApi:function(data,i){varthatth



这里调用循环请求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);
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 &#61; that.data.paramList

console.log(that.data.paramList)
var eachParam &#61; {
"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 &#61; that.data.navbar//选项卡标题
tempNavbar.push(json[0].TypeName)
that.setData({
navbar: tempNavbar,
paramList: tempParam
})
console.log(&#39;for循环打印开始了&#xff1a;&#39;)
console.log(that.data.paramList)
}
}
},
fail: function (resFail) {
console.log(resFail)

},
complete: function (resComp) {
if ((i &#43; 1) >&#61; data.length) {
console.log(&#39;执行完毕了。&#39;)
} else {
that.allTypeApi(that.data.allType, i &#43; 1);
}
},
})
//api请求结束
},


推荐阅读
author-avatar
自由常飞_337
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有