繁体   English   中英

从angularjs中的数组中过滤出对象

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM