getLocation: function (location) {
//通过获取当前位置判断是否签到成功
var that = this
var signstate = null;
wx.getLocation({
type: 'wgs84',
success: function (res) {
that.setData({
getLocation: true,
latitude: res.latitude,
longitude: res.longitude,
})
if (
//位置判断举例
(res.latitude >= location[0] && res.latitude <= location[1]) &&
(res.longitude >= location[2] && res.longitude <= location[3])
) {
signstate = true;
console.log('w1'+signstate);
that.setData({
signstate: true//签到成功
})
console.log('signstate in function:'+that.data.signstate);
} else {
signstate = false;
that.setData({
signstate: false//签到位置错误导致的签到失败
})
}
//console.log(that.data.signstate)
},
fail: function () {
signstate = false;
that.setData({
getLocation: false,
signstate: false//无法获取位置导致的失败
})
}
})
// console.log('signstate in function:'+this.data.signstate);
//return .data.signstate;
},
Sign: function () {
//签到
var that = this;
var user_id = this.data.user_id;
var course_id = this.data.course_id;//课程id
var cr_id = this.data.cr_id;//教室id
console.log("course_id:"+this.data.course_id);
console.log("cr_id:"+this.data.cr_id);
var daytime = this.getDayTime();
var location = [];
query.equalTo('cr_id',cr_id);
query.select('cr_location');
query.find().then(function(data){
location = data[0]._serverData.cr_location;
that.getLocation(location);
console.log('w1:'+that.data.signstate);
}).then(function(){
console.log('w2:'+ that.data.signstate);
console.log('w3:'+that.data.signstate);
}).catch(function(error) {
// 这个错误处理函数将被调用,错误信息是 '出错啦'.
console.error(error.message);
});
},
w1true和signstate in function:true是在query.find().then()中调用getLocation方法得到,w1:null是在这之后让控制台输出的的,而w2:null,w3:null是在后面一个.then()中调用控制台输出的,请问为什么不应该是先执行输出方法中的控制台语句再输出.then()中的控制台语句?