1

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.

8
  • 1
    Note you are calling asyncEach (no 'h') Commented Jan 5, 2014 at 6:08
  • thats not the issue, its a copy paste typo sorry - i fixed the typo thanks Commented Jan 5, 2014 at 6:09
  • Your code results in a syntax error, as you're missing a ). Commented Jan 5, 2014 at 6:12
  • $$('.dateInputs') should be $j('.dateInputs') Commented Jan 5, 2014 at 6:14
  • 1
    Nope. that's prototype i believe. What you want is $j there. Commented Jan 5, 2014 at 6:38

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.