这是我的职责。在这里,我想从数组中过滤对象并将其传递给note变量,当我运行程序时,它显示var note变量未定义,我该怎么办
查看下面的代码
datepicker.onSelect = function (checked) {
var state = (checked) ? 'selected' : 'unselected';
$scope.calDate = this.toLocaleDateString();
var note = $scope.tooltipsArray.filter(function (items) { return items.date === '$scope.calDate' })[0];
ModalService.showModal({
templateUrl: 'scripts/directives/calendar/calendarModal.html',
controller: 'calendarModal',
inputs: {
calendarDate: $scope.calDate,
calendarNote: null,
dateSelected: state
},
size: 'sm'
}).then(function (modal) {
modal.element.modal();
});
};
答案 0 :(得分:0)
我在您的代码中看到的一个问题是您使用 $ scope.calDate 作为字符串
将'$ scope.calDate'更改为$ scope.calDate
var note = $scope.tooltipsArray.filter(function (items) { return items.date === $scope.calDate })[0];
还要获取当前的localeDateString,请使用以下代码
$scope.calDate = new Date().toLocaleDateString();
Stack Blitz
https://stackblitz.com/edit/angularjs-szy529?file=home/home.controller.js