【发布时间】:2016-12-23 12:59:02
【问题描述】:
我正在使用 datepicker 作为我的视图。我也使用 angularjs。问题是当我使用 ok 按钮时,它不会改变 ng-model 状态。它仍然显示 ng-empty。我用这个值来计算另一个字段,你可以忽略它。 只需告诉 imake ok 按钮如何激活而不是 onClose?当用户选择月份和年份时,我需要确保 ng-model 发生变化。 我的日期选择器:
$(function () {
$('.date-picker').datepicker({
yearRange: "-5:+0",
showButtonPanel: true,
dateFormat: 'MM yy',
changeMonth: true,
changeYear: true,
closeText: 'OK',
beforeShow: function () {
$(this).datepicker('widget').addClass('hide-calendar');
if ((selDate = $(this).val()).length > 0) {
iYear = selDate.substring(selDate.length - 4, selDate.length);
iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5), $(this).datepicker('option', 'monthNames'));
$(this).datepicker('option', 'defaultDate', new Date(iYear, iMonth, 1));
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
}
},
onClose: function (dateText, inst) {
$(this).datepicker('widget').removeClass('hide-calendar');
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
var monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
var mN = $("#monthNo").val();
if (mN == '') {
return;
}
var tm = parseInt(month) + parseInt(mN-1)
if (tm > 11) {
tm = tm - 12;
year =parseInt(year) + 1;
}
$("#to").val(monthNames[parseInt(tm)] + " " + year);
}
}).click(function () {
$('.ui-datepicker-calendar').hide();
}).attr("readonly", true);
});
【问题讨论】:
-
你能帮帮我吗?@Bharti Sharma
-
日期选择器在角度 evn 之外,点击更新您需要运行 $scope.$apply() 的模型
-
我在哪里可以实现 $scope.$apply() ?
-
如果您可以使用日期选择器设置小提琴,我可以向您展示具体方法。但只是从上面的 id 来看,在链接的回调中的某处说 .click
标签: angularjs jquery-ui jquery-ui-datepicker