typescript - 事件监听器参考打字稿函数
问题描述
我正在尝试添加引用本地 TypeScript 函数的事件侦听器。一旦我得到我的位置,我会循环我的响应,为每个标记添加一个事件。
for (count = 0; count < this.historyList.length; count++) {
let position = new google.maps.LatLng(this.historyList[count].latitude,
this.historyList[count].longitude)
marker = new google.maps.Marker({position: position});
marker.setMap(this.map);
//now add an event to the marker.
google.maps.event.addListener(marker, 'click', (function (marker) {
return function () {
infowindow.setContent(address);
infowindow.open(this.map, marker);
console.log(marker.getPosition().lng())
this.map.setCenter(marker.getPosition() as google.maps.LatLng);
}
})(marker));
现在这对于单击标记很有效,但我无法引用我的任何打字稿函数,所以我尝试添加一个不同的侦听器:
google.maps.event.addListener(marker, 'click', () => {
this.highlightItem(3);
});
这有效(使用=>)允许我访问我的本地打字稿,但现在我不会得到被点击的特定标记,它总是会引用循环中的最后一个。如何获取已单击的标记和参考打字稿方法?
谢谢
解决方案
推荐阅读
- javascript - 调度新的 redux 操作时如何正确删除对象子字段?
- r - 使用 tidyverse 替换一些字符值
- flutter - Flutter - 条码扫描器和 ListView
- arduino - Arduino for 循环完全不起作用
- google-app-engine - 通过 App Engine 中的 Google Auth Library 请求 ID 令牌时出现混合内容错误
- reactjs - React js超过最大更新深度
- django - Pytest 在 Django 的文件夹中看不到文件
- javascript - JavaScript type="module" 在 iOS 中不起作用
- c# - 由于缺少原始 UI.exe 文件,不同版本的 ClickOnce 应用程序导致崩溃
- google-colaboratory - 当 logdir 存储在变量中时,Tensorflow 找不到日志