模拟标记在Ember的Google Map上

时间:2014-03-02 20:31:52

标签: google-maps ember.js

在Ember的地图上渲染标记。

我希望/map能够在地图上显示一系列不同类型的标记。我希望这些标记在地图上完全模块化。

这是我的MapRoute

App.MapRoute = Ember.Route.extend({
  setupController: function(controller, model) {
    this.store.find('marker', this.paramsFor(this.routeName)).then(function(result){
      this.controllerFor('markers').set('model', result);
    }
  }
});

我有MapView初始化谷歌地图对象,并且有一个名为map的属性,其中包含谷歌地图对象。

在我的MarkersController

App.MarkersController = Ember.ArrayController.extend({
   arrayContentDidChange: function() {
      // Accesss the google map object in the MapView
      // Render all markers
   }
});

如何从MarkersController中的MapView访问Google地图?

一种想法是让MapController知道MapView并让MarkersController“需要”MapController。但我觉得控制器知道它的观点是不好的做法。

1 个答案:

答案 0 :(得分:1)

您应该可以使用MapViewMarkersView内访问this.get('parentView')

App.MarkersView = Ember.View.extend({
  didInsertElement: function() {
     console.log(this.get('parentView'));
  }
});

这是您的视图逻辑和行为应该存在的地方。如果您需要进行数据操作,我应该按照您的说法在控制器中使用needs