我有两个日期选择器和一个下拉列表,当我选择下拉列表时,我希望日期选择器根据所选项目进行更改,请参阅下面的代码。
$scope.toolbarOptions = {
items: [{
template: "<label>From</label>"
}, {
template: "<input kendo-date-picker k-ng-model='startDate'/>",
overflow: "never"
}, {
template: "<label>To</label>"
}, {
template: "<input kendo-date-picker k-ng-model='endDate'/>",
overflow: "never"
}, {
template: "<label>Period</label>"
}, {
template: "<select kendo-drop-down-list k-value-primitive='true' k-change='periodChanged' k-ng-model='selectedPeriod' k-data-source='periodDataSource' style='width:150px'/>",
overflow: "never"
}]};
$scope.periodChanged = function () {
var value = $scope.selectedPeriod;
var day = new Date(), year = day.getFullYear(), month = day.getMonth();
switch (value) {
case "Today":
$scope.startDate = day;
$scope.endDate = day;
return;
case "This Week":
var first = day.getDate() - day.getDay();;
var last = first + 6;
$scope.startDate = new Date(day.setDate(first));
$scope.endDate = new Date(day.setDate(last));
return;
case "This Month":
$scope.startDate = new Date(year, month, 1);
$scope.endDate = new Date(year, month + 1, 0);
return;
case "This Year":
$scope.startDate = new Date(year, 0, 1, 23, 59, 59);
$scope.endDate = new Date(year + 1, 0, 0);
return;
default:
return;
}
}
但是在选定项目更改后,日期选择器不会直接更改,当我选择另一个项目时,先前分配的值会显示在日期选择器中。有人可以帮忙吗?
答案 0 :(得分:0)
只需调用$ scope。$ digest()可以帮助更新DatePicker