I have the following javascript code – augmented with the dojo library:
[CODE]function theAdminDojoTools() {
this.wireUserDeActivateEvents = function () {
var userDiv = document.getElementById(“userListDiv”);
var deactiveButtons = userDiv.getElementsByClassName(“deactivateUserButton”)
for (var i = 0; i < deactiveButtons.length; i++) {
deactiveButtons[i].onclick = this.deactivateUser;
}
}
this.deactivateUser = dojo.hitch(this, function (evt) {
var UserId = evt.srcElement.dataset.userid;
require([“dojo/request/xhr”], function (xhr) {
var url = “/users/DeactivateUser”
var postData = { id: UserId }
new xhr(url, { method: “POST”, data: postData }).then(this.deactiveUserSuccess(), this.deactiveUserFailure());
});
});
this.deactivateUserSuccess = dojo.hitch(this, function (data) {
alert(“user deactivated.”)
});
this.deactivateUserFailure = function (data) {
alert(“failure deactivate”)
}
var self = this;
}
The problem I’m having is in the deactivateUser function. When this function is called, in the xhr promise, deactiveUserSuccess is always undefined (as is deactiveUserFailure ? ). It seems that ‘this’ in this context refers to the html element whose click event called deactivateUser .
I’ve tried referring to ‘self’ instead of ‘this’. No success.
I’ve tried removing the various dojo.hitch functions. No success there either.
‘this’ always refers to something other than ‘theAdminDojoTools’.
I have similar functionality in other parts of my app and it works just fine. I can’t help but think I’ve overlooked something.
Any ideas?