我有2个函数,想从另一个函数调用一个函数并得到2个值。
renderMap: function(){
// here I need to call getCurrentLocation function and get 2 values - lat and lng from it.
console.log(lat, lng);
},
getCurrentLocation: function() {
var me = this,
lat,
lng;
Ext.device.Geolocation.getCurrentPosition({
success: function(position) {
me.lat = position.coords.latitude;
me.lng = position.coords.longitude;
}
});
},
请告知如何正确地做到这一点。
答案 0 :(得分:2)
me
时, Ext.device.Geolocation.getCurrentPosition
不再存在。
到那时你处于不同的上下文或范围,Ext.device.Geolocation
类对me
变量一无所知。
在方法的开头,这指的是你的控制器,但是你正在调用getCurrentPosition
类的Ext.device.Geolocation
方法,因为你没有将任何参数传递给方法me
是undefined
。
它认为你可以用Ext.bind解决这个问题
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext-method-bind
同时寻找电话并在JavaScript中申请:)
最好的问候@ code4jhon
答案 1 :(得分:0)
您可以从getCurrentLocation返回对象,例如:
return {lat:xxxx, lng:yyyy};