I’m following miamicoder’s sencha touch 2 tutorial with great success (http://miamicoder.com/2012/how-to-create-a-sencha-touch-2-app-part-2/), however because I’m still a newbie to this my javascript knowledge is restricting me some what.
What I want to do is call a javascript function stored in the controller but pass it local variables. Here’s my code thats declared in the initialize of one of my views:
var geo = Ext.create('Ext.util.Geolocation', {autoUpdate: false, listeners: {
locationupdate: function(geo) {
console.log('Got location: ',geo);
findCurrentAddress(geo,"txtFrom");
},
//locationerror: {fn: this.onGotLocation, scope: this }
locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
alert("deal with this later")
}
}
});
geo.updateLocation();
and then findCurrentAddress is defined as:
function findCurrentAddress(geo, txt){
alert("do some stuff with the geo object");
}
How can I move this function over to the controller and still make it accessible to this view? Like what the tutorial does with the onNewButtonTap event on the link provided above.
The end result is the same, but I’d like to keep things clean but keeping functions out of the way.
I tried doing:
locationupdate: {fn: this.onGotLocation, scope: this }
and wiring the necessary code in the controller, which worked except I lose the the geo object with lat/long properties (at least, I dont know how to pass it!)
Any help/tips/pointers much appreciated! 🙂
Why not fire and event from the view and subscribe to that event in your controller?
something like this:
and listen for your get_loc_update event in the controller (or whatever you call it), which will pass the geo object