我的应用程序中有一个timepicker和daypicker。我需要将这些值传递给另一个对象。但是,由于时间/日期输入为空,因此对象在页面加载时返回undefined。所以我的问题是如何在选择时间/日期之后更新对象中的未定义值。
时间和日期选择器的代码:
$scope.startTime = function () {
$scope.time = $filter('date')($scope.time, 'HH:mm:ss');
$rootScope.time = $scope.time;
console.log($rootScope.time);
}
$scope.startDate = function() {
$scope.dateStart = $filter('date')($scope.dateStart, 'yyyy-MM-dd');
$rootScope.startDate = $scope.dateStart;
console.log($rootScope.startDate);
}
$scope.endDate = function() {
$scope.dateEnd = $filter('date')($scope.dateEnd, 'yyyy-MM-dd');
$rootScope.endDate = $scope.dateEnd;
console.log($rootScope.endDate);
}
$scope.selectedDay = function () {
$rootScope.day = $scope.day;
console.log($rootScope.day);
}
需要更新值的对象:
$rootScope.schedule = {
"@": {
"let_run": "yes",
"when_holiday": "ignore_holiday",
// "begin":"06:30",
"begin": $rootScope.time,
},
"weekdays": {
"day": {
"@": {
"day": $rootScope.day
// "day":"0"
}
}
}
};
console.log($rootScope.schedule);
答案 0 :(得分:1)
通过更新每个功能中的计划对象,我能够解决这个问题。例如:
$scope.startTime = function () {
$scope.time = $filter('date')($scope.time, 'HH:mm:ss');
$rootScope.time = $scope.time;
$rootScope.schedule['@'].begin = $rootScope.time;
console.log($rootScope.time);
}