我有一个谷歌地图的视图,我希望它公开地图,以便我可以从另一个对象绑定到它。问题是,因为我只能实例化地图上的didInsertElement
(直接实例化它不会工作,因为div尚未渲染)我无法访问映射的真正值(它总是返回null)。无法访问属性在ember.js视图
这里是我的代码:
Places = Ember.Application.create();
Places.MapView = Ember.View.extend({
tagName : 'div',
map : null,
didInsertElement : function() {
this._super();
this.set('map', new google.maps.Map($('#map').get(0), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(-33.8665433,151.1956316),
zoom: 15
}));
this.get('map'); // Returns the value of the map OK
}
});
Places.searchController = Ember.Object.create({
mapBinding: 'Places.MapView.map' // Doesn't work
}
这里是模板:
<script type="text/x-handlebars">
{{#view Places.MapView id="map"}}{{/view}}
</script>
如果我设置内MapView
任何其他财产直接我没有问题,结合它。有关如何解决这个问题的任何想法?
我试图'Places.mapView = Places.MapView.create({})'和'{{#view Places.mapView ID = “地图”}} {{/视图}}'但随后的地图没有出现在屏幕上。 – Johnny 2012-02-23 13:58:43