[英]Filter out object from an array in angularjs
This is my function. 这是我的职责 In here I want to filter object from an array and pass it in to the note variable When I run the program its shows var note variable is undefined what can I do for that
在这里,我想从数组中过滤对象并将其传递给note变量,当我运行程序时,它显示var note变量未定义,我该怎么办。
Review below code 查看以下代码
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();
});
};
One issue I can see in your code is you are using $scope.calDate as string 我在您的代码中看到的一个问题是您使用$ scope.calDate作为字符串
change '$scope.calDate' to $scope.calDate
将'$ scope.calDate'更改为$ scope.calDate
var note = $scope.tooltipsArray.filter(function (items) { return items.date === $scope.calDate })[0];
And Also to get the current localeDateString , use the below code 同样,要获取当前的localeDateString,请使用以下代码
$scope.calDate = new Date().toLocaleDateString();
Stack Blitz 堆叠闪电战
https://stackblitz.com/edit/angularjs-szy529?file=home/home.controller.js https://stackblitz.com/edit/angularjs-szy529?file=home/home.controller.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.