未存储输入字段中的日期
Date from input field not being stored
我设置了 Angular-Meteor 应用程序以允许用户编辑他们的出生日期。我在输入字段上使用 bootstrap3-datepicker。
表单中的输入域是这样定义的:
<div class="form-group">
<label for="dateOfBirth" class="control-label">Date of Birth:</label>
<input type="date" id="dateOfBirth" class="form-control" ng-model="profileEdit.profile.dateOfBirth"/>
</div>
选择和显示日期在前端工作正常,但当我保存我的表单时没有存储日期(所有其他数据是)。如果在使用表单编辑记录之前存在日期,该日期将丢失。
这是我的控制器:
class ProfileEdit {
constructor($stateParams, $scope, $reactive) {
'ngInject';
this.profile = Meteor.user().profile;
$('#dateOfBirth').datepicker({
format: "dd.mm.yyyy",
weekStart: 1,
startDate: "01.01.1940",
startView: 2
});
}
save() {
var profile = {
firstName: this.profile.firstName,
lastName: this.profile.lastName,
gender: this.profile.gender,
dateOfBirth: this.profile.dateOfBirth,
level: this.profile.level,
description: this.profile.description
}
Meteor.call('users.profile.update', profile, function(error, result) {
if(error){
console.log("error", error);
}
if(result) {
console.log('Changes saved!');
profile = {}
}
});
}
}
在保存表单数据之前将 profileEdit.profile.dateOfBirth
记录到控制台会产生 undefined
。
在我看来,我已经失去了表格和我的 save()
方法之间的日期。 为什么会这样?
我与另一个日期选择器有同样的问题,似乎当第三方插件更新 DOM 时,它不会更新附加到它的模式。我必须做的是使用日期选择器的事件来捕捉变化并以编程方式更新字段,IE:
$('.datepicker').datepicker()
.on('changeDate', function(e) {
// update your model here, e.date should have what you need
});
http://bootstrap-datepicker.readthedocs.io/en/latest/events.html
我设置了 Angular-Meteor 应用程序以允许用户编辑他们的出生日期。我在输入字段上使用 bootstrap3-datepicker。
表单中的输入域是这样定义的:
<div class="form-group">
<label for="dateOfBirth" class="control-label">Date of Birth:</label>
<input type="date" id="dateOfBirth" class="form-control" ng-model="profileEdit.profile.dateOfBirth"/>
</div>
选择和显示日期在前端工作正常,但当我保存我的表单时没有存储日期(所有其他数据是)。如果在使用表单编辑记录之前存在日期,该日期将丢失。
这是我的控制器:
class ProfileEdit {
constructor($stateParams, $scope, $reactive) {
'ngInject';
this.profile = Meteor.user().profile;
$('#dateOfBirth').datepicker({
format: "dd.mm.yyyy",
weekStart: 1,
startDate: "01.01.1940",
startView: 2
});
}
save() {
var profile = {
firstName: this.profile.firstName,
lastName: this.profile.lastName,
gender: this.profile.gender,
dateOfBirth: this.profile.dateOfBirth,
level: this.profile.level,
description: this.profile.description
}
Meteor.call('users.profile.update', profile, function(error, result) {
if(error){
console.log("error", error);
}
if(result) {
console.log('Changes saved!');
profile = {}
}
});
}
}
在保存表单数据之前将 profileEdit.profile.dateOfBirth
记录到控制台会产生 undefined
。
在我看来,我已经失去了表格和我的 save()
方法之间的日期。 为什么会这样?
我与另一个日期选择器有同样的问题,似乎当第三方插件更新 DOM 时,它不会更新附加到它的模式。我必须做的是使用日期选择器的事件来捕捉变化并以编程方式更新字段,IE:
$('.datepicker').datepicker()
.on('changeDate', function(e) {
// update your model here, e.date should have what you need
});
http://bootstrap-datepicker.readthedocs.io/en/latest/events.html