0

一点上下文:我正在尝试使用 css 类在 JQuery DatePicker 中标记日期以指示它们的可用性级别。(绿色日期 = 大量可用,橙色日期 = 部分可用,禁用 = 无可用)。我写了一个服务,结果是

ViewBag.AvailabilityTimeMap = IDictionary<DateTime, int> 
//int is the availability/capacity of the specified date.

现在我希望将其写入视图,以便 DatePicker 的 beforeShowDay 函数可以将它传递的日期与字典中的 DateTime 匹配。

$('#_uiAppCalendarDiv').datepicker({
    beforeShowDay: renderCalendarCallback
});

var dateMap = @Html.Raw(SomeSortOfSerialization(ViewBag.AvailabilityTimeMap));

function renderCalendarCallback(date) {
    //eliminate weekends
    if ($.datepicker.noWeekends(date) == false){
        return false;
    }

    for(var index in dateMap) {
      if (index.key == date.toJSON()){ 
        //apply the appropriate css
        return true;
      }
    }
    //date is not in the availability map (should not happen).
    return false;    
}

我认为使用正确的“SomeSortOfSerialization”应该是可能的吗?看起来 Json.Encode 对 DateTime 使用了一种奇怪的格式,而 javascript 对此无能为力。

4

0 回答 0