作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个表格,标题中有 5 个单元格,每个单元格对应一个星期(例如:第 01 周、第 02 周等等)。
在第一个单元格中,周是这样给出的:
<div class="monthCells">Week {{vm.selectedPeriod}}</div>
return moment.utc(this.date).format("WW");
return moment.utc(this.date).format("WW");
{{vm.selectedPeriod}}
{{vm.selectedPeriod +1}}
{{vm.selectedPeriod +2}}
{{vm.selectedPeriod +3}}
{{vm.selectedPeriod +4}}
{{vm.date | amDateFormat : 'WW'}}
{{vm.date | amAdd : '1' : 'w' | amDateFormat : 'WW'}}
{{vm.date | amAdd : '2' : 'w' | amDateFormat : 'WW'}}
最佳答案
我会用一个简单而智能的过滤器来做到这一点,就像我在这个 中创建的那样>> Demo fiddle :
看法
<div ng-controller="MyCtrl">
<div class="monthCells">Week {{currentDate|dateWeekFilter:0}}</div>
<div class="monthCells">Week {{currentDate|dateWeekFilter:1}}</div>
<div class="monthCells">Week {{currentDate|dateWeekFilter:2}}</div>
<div class="monthCells">Week {{currentDate|dateWeekFilter:3}}</div>
</div>
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function ($scope) {
$scope.currentDate = moment.utc();
});
myApp.filter('dateWeekFilter', function () {
return function (date, weeksToAdd) {
return moment(date).add(weeksToAdd, 'w').format("WW");
}
});
selectedPeriod
范围和日期选择器
<div ng-controller="MyCtrl">
<datepicker>
<input ng-model="datePickerDate" ng-change="dateChanged()" type="text"/>
</datepicker>
<div class="monthCells">Week {{currentDate|dateWeekFilter:selectedPeriod}}</div>
<div class="monthCells">Week {{currentDate|dateWeekFilter:selectedPeriod+1}}</div>
<div class="monthCells">Week {{currentDate|dateWeekFilter:selectedPeriod+2}}</div>
<div class="monthCells">Week {{currentDate|dateWeekFilter:selectedPeriod+3}}</div>
</div>
var myApp = angular.module('myApp',['720kb.datepicker']);
myApp.controller('MyCtrl', function ($scope) {
//Init
$scope.currentDate = moment.utc();
$scope.datePickerDate = $scope.currentDate.toDate();
$scope.selectedPeriod = 0;
//date change handling
$scope.dateChanged = function () {
$scope.currentDate = moment.utc($scope.datePickerDate);
}
});
myApp.filter('dateWeekFilter', function () {
return function (date, weeksToAdd) {
return moment(date).add(weeksToAdd, 'w').format("WW");
}
});
关于AngularJS 如何向返回日期的函数添加 +1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48863792/
我是一名优秀的程序员,十分优秀!