我正在尝试将数据从 Google Map InfoWindow 传递到 Info Page。我能够传递和访问数据。
但是,每次重新打开 infoWindow 时,页面都会触发 i+1,相互叠加。
例如,第一次打开信息窗口时,点击应用按钮,它将转到信息页面。 关闭InfoWindow并重新打开,再次点击Apply按钮,会打开两次Info Page,如果重复则继续加1过程。
过程:
map -> 创建标记 -> 设置 content 变量 -> 创建 infoWindow -> 设置标记以在单击时打开 infoWindow -> infoWindow 随内容一起出现 -> 单击 APPLY 在 infoWindow 上 -> 直接到 InfoPage ONCE-> 关闭 InfoPage -> 直接返回 Map 并打开 infoWindow 和内容。 (点击 Apply 将再次进入 InfoPage 但只有 ONCE) -> close infoWindow -> 点击 marker -> 信息窗口显示。 -> 点击信息窗口中的“APPLY”-> 直接进入“InfoPage” TWICE -> 关闭返回第一个InfoPage -> 关闭返回使用 infoWindow 进行映射 -> 关闭信息窗口,显示带有标记的 map 。 -> 点击标记重复,InfoPage 出现三次。
基本上每次 InfoWindow 关闭并再次打开时,InfoPage 都会递增 1。
我从 console.log 中看到的是,当 InfoWindow 重新打开时,它将创建另一个数组,因为 click eventlistener 被触发。我曾尝试使用 oneTime 函数,运行事件一次,以及其他方法,但都失败了。
欢迎对问题发表评论。任何建议表示赞赏。提前致谢:)
GoogleMapProvider.ts
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { App } from 'ionic-angular';
constructor(
public http: Http,
public app:App,
) {
}
addMarker(lat: any, lng: any , listingID:any): void {
let latLng = new google.maps.LatLng(lat, lng);
let marker = new google.maps.Marker({
map: this.map,
animation: google.maps.Animation.DROP,
position: latLng,
});
this.markers.push(marker);
this.addInfoWindow(marker,listingID);
}
addInfoWindow(marker,listingID){
this.http.get('http://localhost/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'].ListingTime + "</p>" +
'<p id="' + infoData['0'].ListingID + '">Apply</p>'
"</ion-item>";
let infoWindow = new google.maps.InfoWindow({
content: content
});
google.maps.event.addListener(infoWindow, 'domready', () => {
let goInfoPage = document.getElementById(infoData['0'].ListingID);
goInfoPage.addEventListener('click', () => {
let pushData = infoData['0'];
let nav = this.app.getActiveNav();
nav.push('InfoPage',{'record':pushData});
})
});
google.maps.event.addListener(marker, 'click', () => {
infoWindow.open(this.map, marker);
});
});
}
Info.ts
ionViewDidLoad()
{
this.selectEntry(this.NP.get("record")); //getting the record
}
最佳答案
设法使用removeEventListener解决
google.maps.event.addListener(infoWindow, 'domready', () => {
let goInfoPage = document.getElementById(infoData['0'].ListingID);
const onClick = () => {
let pushData = infoData['0'];
let nav = this.app.getActiveNav();
nav.push('InfoPage',{'record':pushData});
goInfoPage.removeEventListener('click', onClick);
}
goInfoPage.addEventListener('click',onClick);
});
关于javascript - ionic 2/Angular 2 - 无法将数据从 Google Maps InfoWindow 传递到页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45378792/
我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些
如何在Ruby中按名称传递函数?(我使用Ruby才几个小时,所以我还在想办法。)nums=[1,2,3,4]#Thisworks,butismoreverbosethanI'dlikenums.eachdo|i|putsiend#InJS,Icouldjustdosomethinglike:#nums.forEach(console.log)#InF#,itwouldbesomethinglike:#List.iternums(printf"%A")#InRuby,IwishIcoulddosomethinglike:nums.eachputs在Ruby中能不能做到类似的简洁?我可以只
这是我的网络应用:classFront我是这样开始的(请不要建议使用Rack):Front.start!这是我的Puma配置对象,我不知道如何传递给它:require'puma/configuration'Puma::Configuration.new({log_requests:true,debug:true})说真的,怎么样? 最佳答案 配置与您运行的方式紧密相关puma服务器。运行的标准方式puma-pumaCLI命令。为了配置puma配置文件config/puma.rb或config/puma/.rb应该提供(参见examp
我有一个电子邮件表格。但是我正在制作一个测试电子邮件表单,用户可以在其中添加一个唯一的电子邮件,并让电子邮件测试将其发送到该特定电子邮件。为了简单起见,我决定让测试电子邮件通过ajax执行,并将整个内容粘贴到另一个电子邮件表单中。我不知道如何将变量从我的HAML发送到我的Controllernew.html.haml-form_tagadmin_email_blast_pathdoSubject%br=text_field_tag'subject',:class=>"mass_email_subject"%brBody%br=text_area_tag'message','',:nam
我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的
如何将lambda传递给hash.each,以便我可以重复使用一些代码?>h={a:'b'}>h.eachdo|key,value|end=>{:a=>"b"}>test=lambdado|key,value|puts"#{key}=#{value}"end>test.call('a','b')a=b>h.each&testArgumentError:wrongnumberofarguments(1for2)from(irb):1:in`blockinirb_binding'from(irb):5:in`each'from(irb):5from/Users/jstillwell/.rv
我正在尝试将cucumber项目的用户名和密码置于版本控制之外。有没有办法在命令行上手动将用户名和密码等变量传递给Cucumber脚本?我的备份计划是将它们放在一个YML文件中,然后将该文件添加到gitignore,这样它们就不会被置于版本控制中。 最佳答案 所以,我看到了您对铁皮人的评论,答案是肯定的。cucumberPASSWORD=my_passwordPASSWORD被设置为环境变量,您可以通过将其引用为ENV['PASSWORD']来使用它的值。例如,browser.text_field(:id=>'pwd').setEN
我正在尝试将自定义方法与here-doc一起使用,并希望传递参数(没有业务案例,我只是想学习ruby)。在这种情况下有没有办法传递参数?这是我目前所拥有的。方法简单,效果很好。defmeth1self.upcaseendstr1=现在,我想让我们放弃一些参数并尝试不同的变体,irb给了我一个茫然的眼神。#variation1defmeth2( 最佳答案 我猜这就是您要尝试做的:defmeth2(str1,str2)str1.upcase+"..."+str2.downcaseendstr2=meth2("SOMESTRING\n
也许这听起来很荒谬,但我想知道这对Ruby是否可行?基本上我有一个功能...defadda,bc=a+breturncend我希望能够将“+”或其他运算符(例如“-”)传递给函数,这样它就类似于...defsuma,b,operatorc=aoperatorbreturncend这可能吗? 最佳答案 两种可能性:以方法/算子名作为符号:defsuma,b,operatora.send(operator,b)endsum42,23,:+或者更通用的解决方案:采取一个block:defsuma,byielda,bendsum42,23,