首页 > 解决方案 > 如何将焦点从文本的点击事件转移到 googleplaces 自动完成输入?

问题描述

需要您对我正在尝试开发的应用程序的帮助。所以我使用了 react native googleautoplaces complete 作为位置,这在第一个文本输入中显示。

加载时的页面根据我使用的地理编码器和地理位置代码获取当前位置。

我需要的是,当我单击“更改”链接时,它应该聚焦或选择位置输入。页面设计谷歌自动完成代码code2

如果我使用 ref,我可以这样做吗?如果是,如何添加多个 ref,因为自动完成中已经使用了另一个 ref。自动完成内部使用的 ref 方法,它采用地址值。

标签: javascriptreact-nativefocusgoogleplacesautocomplete

解决方案


<GooglePlacesAutocomplete 
...
ref={(ref) => { this.ref_location = ref }

//your element where the "Change" is being pressed. I used a button just as an example

<Button
    title="Change"
    onPress={() => { this.ref_location.focus(); }}
/>

推荐阅读