Reputation: 1848
I am writing a Zendesk App. I need to make an ajax request after selecting something with jquery autocomplete:
twTicketsRecvd: function(data) {
this.$("#tags").autocomplete({
source: descriptions,
select: function(event,ui){
this.addTwTicket(event,ui)
}
});
},
addTwTicket: function(event,ui) {
this.ajax('addMapping', 1, 12442)
//do some other stuff
}
I get a this.addTwTicket is not a function error
When I put the this.ajax() call inside the autocomplete select function, the this.ajax() is not found.
This has probably more to do with JS scoping than with zendesk itself, which I am unfortunately not very familiar with.
Upvotes: 0
Views: 430
Reputation: 21430
My guess would be that within the autocomplete this
is likely to take on a new definition, so you will want to alias it like so:
var _this = this;
twTicketsRecvd: function(data) {
$("#tags").autocomplete({
source: descriptions,
select: function(event,ui){
_this.addTwTicket(event,ui)
}
});
},
addTwTicket: function(event,ui) {
_this.ajax('addMapping', 1, 12442)
//do some other stuff
}
Upvotes: 1