gpt4 book ai didi

javascript - 如何在 addEventListener 中移除 EventListener?

转载 作者:搜寻专家 更新时间:2023-10-30 21:08:30 24 4
gpt4 key购买 nike

<分区>

我有一个 addEventListener 会根据点击次数触发多次,如何确保它只运行一次?我尝试使用 removeEventListener 但它根本没有运行。

感谢任何帮助和建议。提前致谢:)

Provider.ts

addInfoWindow(marker,ListingID){

this.http.get(this.baseURI + '/infoWindow.php?id=' + ListingID)
.map(res => res.json())
.subscribe(Idata => {

let infoData = Idata;

let content = "<ion-item>" +
"<h2 style='color:red;'>" + infoData['0'].ListingTitle + "</h2>" +
"<p>" + infoData['0'].ListingDatePosted + ' ' + infoData['0'].ListingStartTime + "</p>" +
"<p> Salary: $" + infoData['0'].ListingSalary + "</p>" +
'<p id="' + infoData['0'].ListingID + '">Apply</p>'
"</ion-item>";

console.log("CREATING INFOWINDOW WITH CONTENT");
let infoWindow = new google.maps.InfoWindow({

content: content

});

google.maps.event.addListener(infoWindow, 'domready', () => {

let goInfoPage = document.getElementById(infoData['0'].ListingID);

console.log("GETTING PAGE ID");

//let it run only once, currently will increment by 1 if infoWindow if closed and reopen
goInfoPage.addEventListener('click', () => {

let pushData = infoData['0'];

console.log("GETTING PAGE DATA");

let nav = this.app.getActiveNav();

console.log("PUSHHING TO PAGE");

nav.push('StoreInfoPage',{'record':pushData});

})

goInfoPage.removeEventListener('click', () => {
console.log("REMOVE EVENT LISTENER"); // did not run
});

});


google.maps.event.addListener(marker, 'click', () => {
console.log("MARKER CLICKED, OPENING INFOWINDOW");
infoWindow.open(this.map, marker);

});


});

}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com