微信小程 wx.request 获得的数据,已经获得了,调试时在AppData里可以看到。但如何调到这个数据呢?
我在onload和onshow 里console,都打印不出来。
可用通过this.setData({
参数:值
})
其实就是通过键值对的形式保存在js中,然后在页面就可以直接使用了。
我是想用这个数组进行,给其他数组,代码如下:但一直不成功:
fillArrInstallStep2: function () {
var picker_arrInstallStep = [];
var id_arrInstallStep = [];
var show_arrInstallStep = [];
var that = this;//注意这里必须缓存,不然无法在回调中
//获取数据后进行操作
wx.request({
url: 'http://localhost:45566/WxWebService.asmx/GetK3InstallStepInfo',
method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
header: { 'content-type': 'application/json' },
success: function (res) {
// success
// console.log(res);
// console.log(res.data);
// console.log(res.data.d);
that.setData({
show_arrInstallStep: JSON.parse(res.data.d),
});//这里是that不是this
console.log("show_arrInstallStep=========================>");
console.log(show_arrInstallStep); **//打印出数据的内容,是为什么啊。**
show_arrInstallStep.forEach(function (e) {
picker_arrInstallStep.push(e.FName);
id_arrInstallStep.push(e.FInstallStepID);
});
},
fail: function () {
// fail
},
complete: function () {
// complete
}
});
// this.setData({ show_arrInstallStep: show_arrInstallStep, picker_arrInstallStep: picker_arrInstallStep, id_arrInstallStep: id_arrInstallStep });
},
可用通过this.setData{},数据就在这里面了!