setdata滞后反应
getid:function(cb){
try {
var id = wx.getStorageSync(‘id’)
} catch (e) {
// Do something when catch error
}
typeof cb == “function” && cb(id)
},
onLoad: function (options) {
var that = this
that.getid(function(id){
that.setData({ show: (id == 0) ? ‘首页地址获取有误’ : ‘本次查询结果ID为’ + id })
})
}
在wxml页面,直接<view>{{show}}</view>
每次显示初始值,例如没用过就id为0,用过了显示上次id
把getstoragesync换做app.globalData,也是一样。到底哪里出错了?
9 回复
getid: function (cb,err){ try { var id = wx.getStorageSync( 'id' ) typeof cb == "function" && cb(id) } catch (e) { // Do something when catch error typeof err == "function" && err(e) } }, |
onLoad: function (options) { var that = this that.getid( function (id){ that.setData({ show: (id == 0) ? '首页地址获取有误' : '本次查询结果ID为' + id }) }, function (e){ console.log( '获取id失败' ,e) }) } |