Note that there are some explanatory texts on larger screens.

plurals
  1. POLooping over array of objects
    primarykey
    data
    text
    <p>I'm working on an asp.net app that is utilizing a lot of jQuery UI controls particularly the datepicker.</p> <p>In my web service I am making a call to the database and retrieving a list of objects and then passing them back to my javascript where I parse them out into an array containing 1 or more objects that look like this:</p> <p><a href="http://s7.postimage.org/9nsq80rnv/JSON_object.png" rel="nofollow noreferrer">javascript object http://s7.postimage.org/9nsq80rnv/JSON_object.png</a></p> <p>I need to include some kind of logic in which I can loop through this array of objects and check to see if a javascript Date falls in between the EndDate and StartDate properties of the object so that I can apply a css style for the DatePicker. First question, is there a way to convert the EndDate/StartDate property from this format to a valid javascript Date? And if so how can I iterate over the array and apply the logic to see if the date falls inside the range?</p> <p>Any help is greatly appreciated!</p> <p>Edit: I noticed the image here is kind of hard to see you can more clearly read the properties here:</p> <p><a href="http://postimage.org/image/vmz4v88hz/" rel="nofollow noreferrer">image link</a></p> <p>As requested here is some example code:</p> <pre><code>function createDateRangesForCalendar() { $.ajax({ type: "POST", url: "../Services/BookingService.asmx/GetCalendarDateRanges", contentType: "application/json; charset=utf-8", dataType: "json", async: false, success: function (response) { dateRanges = $.parseJSON(response.d); }, error: function (xhr, textStatus, thrownError) { alert(textStatus); alert(thrownError); } }); } function markInvalidDates(date) { var isHoliday = false; dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear(); isHoliday = checkIsHoliday(date); if ($.inArray(dmy, invalidDays) == -1) { for (var i = 0; i &lt; dateRanges.length; i++) { // if date falls in between start and end date of object[i] return something like: return [true, "holiday", "Holiday Rates Apply - Minimum 14 days"]; // else loop through to the next object and try there } if (isHoliday == true) { return [true, "holiday", "Holiday Rates Apply - Minimum 14 days"]; } else { return [true, ""]; } } else { return [false, "unavailable", "Unavailable"]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload