我有以下数组,其中包含代表星期几的数字:
var available = [1, 2, 3... whatever];
它从周期动态加载日期:
for (var i = 0; i < data.length; i++) {
var pos = data[i].position;
available.push(pos);
}
我指定了一个名为“several几天”的功能来过滤可用天数:
$scope.severalDays = function(date) {
// I want access to available array here
}
在我的HTML中,我有md-datepicker行:
<md-datepicker ng-model="availableCalendar" md-date-filter="severalDays"></md-datepicker>
我怎么能这样做?
答案 0 :(得分:1)
<强> ** **解决强>
$scope.severalDays = function (date) {
var day = date.getDay(); //I got generic day from 0 to 6 (0 for sunday, 6 for saturday);
for(var i = 0; i < available.length; i++){
var len = available.length; //length of available array
var currentPos = available[i]; //current position of array
var nextPos = available[(i+1)%len]; //next position of array
var previousPos = available[(i+len-1)%len]; //previous position of array
return day === currentPos || day === nextPos || day === previousPos; //THE RETURN
}
}