Reputation: 868
I have a function using prototype for my objects but now in need of making an asynchronous call for setting some inputs the problem is that i am getting $$(...).asyncEach is not a function
here is my code snippet
Customers.prototype.AddDatePickers = function()
{
$j.fn.asyncEach = function(callback){
var i = 0;
var elements = this;
var timer = setInterval(function () {
callback.call(elements[i], elements[i]);
if(++i >= elements.length) clearInterval(timer);
}, 0);
}
$$('.dateInputs').asyncEach(function (input) {
$(this).kendoDatePicker();
});
}
The reason why I have to do this is because there are lots of inputs with date pickers that need to get created so the unresponsive script message shows. I am trying to avoid that and this was given as an answer, my problem is I think (i am new to jquery) is that it is in a prototype function?, usually when I need to use $
i have to use $j
in my prototype functions so that there is no conflict. But with this set up I am not really sure how to make it work.
Upvotes: 1
Views: 246
Reputation: 23803
For the purpose you described, it could be a lot simpler. The following should do.
$('.dateInputs').each(function() {
var element = this;
setTimeout(function() {
$(element).kendoDatePicker();
}, 0);
});
Note: I'm using the standard jquery notation, you can modify it your no-conflict version.
Also, your version has a bug in it that calls the callback
at least once even if the elements were empty.
Upvotes: 1