[英]Filter out object from an array in angularjs
這是我的職責 在這里,我想從數組中過濾對象並將其傳遞給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();
});
};
我在您的代碼中看到的一個問題是您使用$ 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();
堆疊閃電戰
https://stackblitz.com/edit/angularjs-szy529?file=home/home.controller.js
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.