I have a fairly basic inquiry regarding how to stop an .each() loop after the conditions have been met. I have a notification counter that displays the number of Issues within a given timeframe. It works, but if I were select another option, it will add up the notifications, which is not good. Below is an example of Issues within 24 hours. I also have an option for Issues within one week and 30 days.
For example, if I were to select 24 hours, it will show: 2
If I were then to select One Week, it will 12 (One Week = 10)
I've tried 'return false' at the end of the loop, but no luck.
Let me know if you can help me out. Thank you.
// # of Issues within 24 hours
var newIssues, openIssues, closedIssues;
newIssues = 0;
openIssues = 0;
closedIssues = 0;
$('.newIssueCount').text('-');
$('.openIssueCount').text('-');
$('.closedIssueCount').text('-');
$('ul.timeFrameRange li:nth-child(1)').click( function(e) {
e.preventDefault();
$.each(parsedData, function (index, item) {
if (moment(item.CreatedDate).isAfter(twentyFourHours)) {
newIssues++;
$('.newIssueCount').html(newIssues);
if (item.IsClosed == false) {
openIssues++;
$('.openIssueCount').html(openIssues);
}
else if (item.IsClosed == true) {
closedIssues++;
$('.closedIssueCount').html(closedIssues);
}
else if (newIssues == 0 || openIssues == 0 || closedIssues == 0) {
$('.newIssueCount').html('0');
$('.openIssueCount').html('0');
$('.closedIssueCount').html('0');
}
}
return false;
});
});