在我的AngularJS
应用中,我有$scope
这样的
controller.js
$scope.takeovers = {
"_id":"5640989531622c5c28fd41c7",
"activationDate":[{
"start":"2015-10-31T23:00:00.000Z",
"end":"2015-11-05T23:00:00.000Z",
"_id":"5640989531622c5c28fd41cc"
}],
"_id":"5640a14a1a743d001a3a1c94",
"activationDate":[{
"start":"2015-11-07T23:00:00.000Z",
"end":"2015-11-05T23:00:00.000Z",
"_id":"2015-11-12T23:00:00.000Z"
}]
}
在视图中,我使用以下选项生成datepicker
index.jade
datepicker( ng-model="upcoming"
show-weeks="false"
ng-click='selectTakeover(upcoming)'
custom-class='getDayClass(date)')
现在我想让getDayClass(date)
函数将date
与$scope.activationDate
start
和end
进行比较,如果date
介于两者之间start
和end
返回名为highlight-current-date
$scope.getDayClass = function(date) {
//The date object contains ISO-date from datepicker option "custom-class"
//Here I want to compare date with $scope.activationDate to see if date is
//between $scope.activationDate.start and $scope.activationDate.end.
//I know I need to re-format the dates to be able to match them.
//This can be done using $filter('date')(date, 'yyyy-MM-dd:hh:mm')
// if match then var result = 'highlight-current-date';
return result;
}
我试图将date
传递给angular.forEach
函数,该函数遍历$scope.takeovers
但我无法返回工作类,因为每次都会覆盖结果{{1} 1}}迭代,我无法打破它。