google地图Autocomplete怎么区分开blur和place_changed事件?

我需要在未选择谷歌自动完成的下拉列表时触发blur事件,用 new google.maps.Geocoder().geocodeAPI返回的数据

选择下拉列表的地址使用place_changed事件返回的数据

在输入框blur事件触发的时候,如何分辨有没有触发place_changed的事件呢?
place_changed触发得比blur得晚,而且是个异步的事件,感觉不好判断啊

Geocomplete.prototype.init = function () {
  var _this = this;

  _this.autocomplete = new google.maps.places.Autocomplete(_this.dom, {
    types: ['geocode'],
    componentRestrictions: {
      country: 'au'
    }
  });

  _this.autocomplete.setFields([
    'address_component',
    'geometry',
    'formatted_address'
  ]);


  //  Google 搜索出来的下拉列表点击后才会触发的事件,是一个异步的
  _this.autocomplete.addListener('place_changed', _this.fillInAddress.bind(_this));
  //  搜索输入框 Blur 事件
  _this.dom.addEventListener('blur', _this.test.bind(_this));
  /**
   * 我需要在未触发 place_changed 事件的情况下失去焦点的时候, 触发Blur
   * 在触发 place_changed 后 就不需要触发 blur事件了
   * place_changed 是个异步的,会比Blur晚触发
   */
}
阅读 2.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进