Javascript 将值从余烬组件发送到父模板

Javascript 将值从余烬组件发送到父模板,javascript,google-maps,ember.js,ember-components,ember-controllers,Javascript,Google Maps,Ember.js,Ember Components,Ember Controllers,我想将lat和lng从一个余烬组件传递到另一个余烬组件(g-map)。我的把手模板: {{!-- Index.hbs --}} <div class="jumbotron-outside"> <div class="jumbotron"> <h1 class="display-3">See The Weather Outside :)</h1> <p class="lead">This is a simple

我想将
lat
lng
从一个余烬组件传递到另一个余烬组件(
g-map
)。我的把手模板:

  {{!-- Index.hbs --}}
  <div class="jumbotron-outside">
  <div class="jumbotron">
    <h1 class="display-3">See The Weather Outside :)</h1>
    <p class="lead">This is a simple forecast weather.</p>
    <hr class="my-4">
    <p>Just type everything bellow this input text to get all list of the city</p>
    {{text-autocomplete}}
    <p class="lead">
      <button class="btn btn-primary btn-default" href="#" role="button" disabled={{isDisabled}}>Search</button>
    </p>
  </div>
  {{g-map lat=lat lng=lng zoom=zoom}}
</div>
我想将
text autocomplete
组件中的
lat
lng
值传递到
g-map
组件,以便在谷歌地图中绘制标记


谁能解决这个问题(

创建
index.js
控制器文件,并引入
lat
lng
zoom
属性。您可以将此属性传递给组件
文本自动完成
g-map
文本自动完成
此组件应向控制器发送操作,以更新
的新值lat
lng
由于双向绑定,它也将在其他位置自动更新

index.js控制器文件

import Ember from 'ember';
export default Ember.Controller.extend({
    lat:'',
    lng:'',
    zoom:'',
    actions:{
        updateLatAndLng(lat,lng){
            this.set('lat',lat);
            this.set('lng',lng);
        }
    }
});
index.hbs

{{text-autocomplete lat=lat lng=lng updateLatAndLng=(action 'updateLatAndLng')}}
{{g-map lat=lat lng=lng zoom=zoom}}
text-autocomplete.js文件

import Ember from 'ember';
export default Ember.Component.extend({
    didInsertElement() { //dom can be acessed here :)
        var autocomplete = new google.maps.places.Autocomplete($('input')[0]);
        var parent = this.$('input');
        let _this = this;
        google.maps.event.addListener(autocomplete, 'place_changed', function() {
            var place = autocomplete.getPlace();
            lat = place.geometry.location.lat();
            lng = place.geometry.location.lng();
            _this.sendAction('updateLatAndLng',lat,lng); //here we are sendin actions to controller to update lat and lng properties so that it will reflect in all the other places.
        });
    }
});
import Ember from 'ember';
export default Ember.Component.extend({
    didInsertElement() { //dom can be acessed here :)
        var autocomplete = new google.maps.places.Autocomplete($('input')[0]);
        var parent = this.$('input');
        let _this = this;
        google.maps.event.addListener(autocomplete, 'place_changed', function() {
            var place = autocomplete.getPlace();
            lat = place.geometry.location.lat();
            lng = place.geometry.location.lng();
            _this.sendAction('updateLatAndLng',lat,lng); //here we are sendin actions to controller to update lat and lng properties so that it will reflect in all the other places.
        });
    }
});