小程序waferqcloudrequest不能把获取的结果保存到data中
2019-03-15 18:14:57
微信公开课小程序热门讨论关于「小程序waferqcloudrequest不能把获取的结果保存到data中」的小程序开发问题
补充:小程序waferqcloudrequest不能把获取的结果保存到data中
展开:我大体先描述下,下面代码的意思,和我要干的事在购物车页面(前一个页面),用户选中商品后,发给结算页面,参数做成json发过来,但是wx对json参数长度有限制,会被截断所以json中只含有用户选中的商品idgoods_id和数量count结算页面拿到json后在init_goods函数中循环调用服务器api拿到商品信息,逐个把商品的详细信息放到thisdatares中保存,最后在onLoad函数中渲染wxml可是我发现,在request中所做的保存,在渲染的时候thisdatares还是空的,在requestsuccess函数中thisdatares有值,出了requestsuccess函数后,res数组是空的另外,我还发现,在success回调函数中对外部传入的对象所做的修改,退出success函数后也都没有保存到对象中初步考虑,1因为request异步执行,拿不到数据2在调用request的时候,传入的obj是一个副本,所以所做的修改没有反映到原来的地址本人经验和知识已不足以解决,大神们,如果知道我的错误,请不吝指个方向代码如下:pagessettlementsettlementjsvarqcloud=require(vendorwafer2clientsdkindex)varconfig=require(config)varutil=require(utilsutiljs)Page({data:{order_info:{},res:[]},init_goods:function(options){thisdataorder_info=JSONparse(optionsorder_info)letthat=thisfor(variinthisdataorder_infogoods_list){consolelog(i,i)goods_id=thisdataorder_infogoods_list[i]goods_idqcloudrequest({url:${configservicehost}weappGoodsget_goods_info+goods_id,success(result){thatdatarespush(resultdata)把结果放到res中保存},fail(error){utilshowModel(请求失败,error);consolelog(requestfail,error);}})utilrequestPromise(${configservicehost}weappGoodsget_goods_info+goods_id)then(res={用了promise貌似也不行consolelog(request,resdata)callback})}},onLoad:function(options){thisinit_goods(options,()={回调也不行consolelog(callback,thisdatares)thissetData({goods_list:thisdatares})})thisinit_goods(options)consolelog(in_onloadthisdatares:,thisdatares)控制台打印的thisdatares是有结果的thisdataorder_infogoods_list[0]=thisdatares[0]这里的thisdatares是空的thissetData({goods_list:thisdatares})这里的thisdatares是空的},})即速小程序:你把onLoad里面最后两行代码放到request的success里看看
更多有关「小程序waferqcloudrequest不能把获取的结果保存到data中」的讨论可以前往微信公开课小程序参与互动哦!
补充:小程序waferqcloudrequest不能把获取的结果保存到data中
展开:我大体先描述下,下面代码的意思,和我要干的事在购物车页面(前一个页面),用户选中商品后,发给结算页面,参数做成json发过来,但是wx对json参数长度有限制,会被截断所以json中只含有用户选中的商品idgoods_id和数量count结算页面拿到json后在init_goods函数中循环调用服务器api拿到商品信息,逐个把商品的详细信息放到thisdatares中保存,最后在onLoad函数中渲染wxml可是我发现,在request中所做的保存,在渲染的时候thisdatares还是空的,在requestsuccess函数中thisdatares有值,出了requestsuccess函数后,res数组是空的另外,我还发现,在success回调函数中对外部传入的对象所做的修改,退出success函数后也都没有保存到对象中初步考虑,1因为request异步执行,拿不到数据2在调用request的时候,传入的obj是一个副本,所以所做的修改没有反映到原来的地址本人经验和知识已不足以解决,大神们,如果知道我的错误,请不吝指个方向代码如下:pagessettlementsettlementjsvarqcloud=require(vendorwafer2clientsdkindex)varconfig=require(config)varutil=require(utilsutiljs)Page({data:{order_info:{},res:[]},init_goods:function(options){thisdataorder_info=JSONparse(optionsorder_info)letthat=thisfor(variinthisdataorder_infogoods_list){consolelog(i,i)goods_id=thisdataorder_infogoods_list[i]goods_idqcloudrequest({url:${configservicehost}weappGoodsget_goods_info+goods_id,success(result){thatdatarespush(resultdata)把结果放到res中保存},fail(error){utilshowModel(请求失败,error);consolelog(requestfail,error);}})utilrequestPromise(${configservicehost}weappGoodsget_goods_info+goods_id)then(res={用了promise貌似也不行consolelog(request,resdata)callback})}},onLoad:function(options){thisinit_goods(options,()={回调也不行consolelog(callback,thisdatares)thissetData({goods_list:thisdatares})})thisinit_goods(options)consolelog(in_onloadthisdatares:,thisdatares)控制台打印的thisdatares是有结果的thisdataorder_infogoods_list[0]=thisdatares[0]这里的thisdatares是空的thissetData({goods_list:thisdatares})这里的thisdatares是空的},})即速小程序:你把onLoad里面最后两行代码放到request的success里看看
更多有关「小程序waferqcloudrequest不能把获取的结果保存到data中」的讨论可以前往微信公开课小程序参与互动哦!
标签:微信公开课,小程序
「小程序waferqcloudrequest不能把获取的结果保存到data中」热门讨论订阅
方法1:微信扫描微信公开课小程序码即可订阅热门讨论「小程序waferqcloudrequest不能把获取的结果保存到data中」
方法2:微信搜索微信公开课小程序名称进入,即可订阅热门讨论「小程序waferqcloudrequest不能把获取的结果保存到data中」
方法3:微信网页访问即速商店,长按识别微信公开课小程序码即可订阅热门讨论「小程序waferqcloudrequest不能把获取的结果保存到data中」
微信公开课小程序热门讨论「小程序waferqcloudrequest不能把获取的结果保存到data中」由微信公开课原创摘录于微信小程序商店shop.jisuapp.cn,转载请注明出处。
微信公开课热门讨论「小程序waferqcloudrequest不能把获取的结果保存到data中」由微信公开课开发者向微信用户提供,并对本服务内容、数据资料及其运营行为等真实性、合法性及有效性承担全部责任。
微信公开课小程序
更新时间:2019-03-15 18:14:57
>
__methodCallerx27;ofundefined
>-404011cloudfunctionexecutionerror
>,请补充选择商家自营-预付卡销售-发行方类目,并在基础信息处申请该类目,通过
>:host在模拟器中显示无效
>:请在小程序服务页面上架正式(非测试)内容或商品后重新提交审核
>.net 微信小程序 上传图片
>'setTimeout'的问题
>‘三朵里熙SPA主题减压空间’为什么搜索关键词‘三朵里‘搜不到
>‘扫普通链接二维码打开小程序‘中设置为体验版,扫码打开是线上版本
>“cloudfunctions**indexjs”gitignore
>“NO ULINK DEVICE FOUND”是怎么回事
>“万马掌上校园”的类目审核
>“上线了”公司开发的微信小程序怎么样?
>“产品是否一定需要条形码”
>