0

I am working with angularjs ...

I want to implement foreach loop in Jquery

vacationSummaries1 =[{VacationType : "X"},{VacationType  : "Y"}]

$.each(($scope.vacationSummaries1, function () 
{
 alert(this.VacationType);
 }));

this is not iterating

what is wrong with the Syntax ?

1

3 Answers 3

3

You have an extra set of parentheses, remove them:

$.each($scope.vacationSummaries1, function () {
    alert(this.VacationType);
});

Also, I'm not sure if vacationSummaries1really belongs to $scope (I don't know angular).

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

1 Comment

I think you are right. A good IDE or little care could have save from this much headache :). Alternate syntax also helps e.g " $(vacationSummaries1).each(function(){});
1

Your code for $.each is having an extra set of bracket (...). Avoid using brackets without any specific reason. Here due to your extra brackets .each function is taking complete parameter as single and callback function is not calling. And in angularjs forEach is present to iterate.

Comments

0

you can do:

angular.forEach($scope.vacationSummaries1,function(v,i){
  alert(v.VacationType)
});

OR

$.each($scope.vacationSummaries1,function(i,v){
  alert(v.VacationType)
});

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.