Reputation: 415
I can't find out how to delay an event handler for a widget. I bind the event like this:
enable: function () {
this.options.isEnabled = true;
this.element.bind("keyup", $.proxy(this, "_populateList"));
},
I want to call "_populateList" with a delay. but my attempts with setTimeout are not working.
The "_populateList":
_populateList: function (event) {
var that = this;
// do my stuffs
}
Thanks
Upvotes: 0
Views: 379
Reputation: 45599
Try this:
enable: function () {
this.options.isEnabled = true;
var that = this;
this.element.bind("keyup", function(event){
$(this)
.delay(1000) // delayed time in milliseconds
.queue(function(next){
that._populateList(event);
next();
});
});
},
Upvotes: 1