3

GoogleMapオートコンプリートコンポーネントを使用しようとしています。このGoogleJavascriptサービスは、単に入力フィールドにバインドする必要があります。

私のアイデアは、TextFieldを拡張する新しいビューを作成し、次のようにバインドを行うことでした。オートコンプリートコンストラクター(this、オプション)の「this」について疑問があります。簡単に理解できるように、これは私にとって入力コンポーネントです...(おそらくここでのエラー)

App.AutoCompleAddressView = Ember.TextField.extend({
  type: 'text',
  init: function() {
    this._super();
    var options = {
      types: ['(cities)'],
      componentRestrictions: {country: 'fr'}
    };
  autocomplete = new google.maps.places.Autocomplete(this, options);
  }
});

およびhtmlコードテンプレート:

{{view App.AutoCompleAddressView}}

残念ながら、Emberエラーが発生します: Uncaught TypeError:オブジェクトにメソッド'getAttribute'がありません

4

1 に答える 1

7

google.maps.places.AutocompleteにDOM要素が必要な場合は、this。$()を渡す必要があります。私はあなたがdidInsertElementフックでそれをしなければならないと思います。何かのようなもの:

App.AutoCompleAddressView = Ember.TextField.extend({
  type: 'text',
  didInsertElement: function() {
    var options = {
      types: ['(cities)'],
      componentRestrictions: {country: 'fr'}
    };
 //this.$() return the element as an array form, but google autocomplete seems to not accept this. So take the first one.
    new google.maps.places.Autocomplete(this.$()[0], options);
  }
});

最小限の例を追加しました:http://jsfiddle.net/6p6XJ/211/

于 2012-12-20T14:27:47.840 に答える