I want to do an ember js find based on an id.
If an object with that id exists I would like to perform some logic on that object.
So, I do so based on the following code:
Cluey.UsersController = Ember.ArrayController.extend({
keypadNum: "",
loginWithPin: function() {
var res;
console.log("Login with pin: " + this.get('loginPin'));
res = Cluey.User.find({
pin: this.get('loginPin')
});
return res.on('didLoad', function() {
var user;
if (res.get('firstObject') != null) {
user = res.objectAt(0);
return this.doLogin(user);
} else {
return alert("User not found with pin " + this.get('loginPin'));
}
});
},
doLogin: function(user) {
//some code
}
});
The problem is that once I am in the res.on('didLoad') callback, I lose the scope of the controller, and therefore when I try to access this.get("loginPin"), it is returned as undefined.
Does anyone know how to solve this.
thanks!