Google maps 无法访问ember.js视图中的属性

Google maps 无法访问ember.js视图中的属性,google-maps,ember.js,Google Maps,Ember.js,我有一个谷歌地图的视图,我想让它公开地图,这样我就可以从另一个对象绑定到它。问题是,由于我只能在didInsertElement上实例化映射,直接实例化它将无法工作,因为div尚未渲染,但我无法访问映射的真实值,它始终返回null 这是我的密码: Places = Ember.Application.create(); Places.MapView = Ember.View.extend({ tagName : 'div', map : null,

我有一个谷歌地图的视图,我想让它公开地图,这样我就可以从另一个对象绑定到它。问题是,由于我只能在didInsertElement上实例化映射,直接实例化它将无法工作,因为div尚未渲染,但我无法访问映射的真实值,它始终返回null

这是我的密码:

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中设置任何其他属性,那么绑定到它就没有问题。关于如何解决这个问题有什么想法吗?

在searchController中,您绑定到MapView类的map属性。该类没有映射属性。实例化类并运行didInsertElement时,map属性将添加到MapView实例。要使绑定工作,您需要绑定到实例化视图的map属性,而不是类。

在searchController中,您绑定到MapView类的map属性。该类没有映射属性。实例化类并运行didInsertElement时,map属性将添加到MapView实例。要使绑定工作,您需要绑定到实例化视图的map属性,而不是类。

在我的控制器中,我通常绑定到模型对象,而不是视图对象

也许可以尝试将贴图设置为其他对象

Places = Ember.Application.create();

Places.MapData = Ember.Object.create({
    map: null
});

Places.MapView = Ember.View.extend({
    tagName : 'div',    
    map : null,               
    didInsertElement : function() {
        this._super();
        Places.MapData.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
        }));
    }
});

Places.searchController = Ember.Object.create({
    mapBinding: 'Places.MapData.map'
});

在控制器中,我通常绑定到模型对象,而不是视图对象

也许可以尝试将贴图设置为其他对象

Places = Ember.Application.create();

Places.MapData = Ember.Object.create({
    map: null
});

Places.MapView = Ember.View.extend({
    tagName : 'div',    
    map : null,               
    didInsertElement : function() {
        this._super();
        Places.MapData.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
        }));
    }
});

Places.searchController = Ember.Object.create({
    mapBinding: 'Places.MapData.map'
});
我尝试了Places.mapView=Places.mapView.create{}和{{view Places.mapView id=map}{{/view}}},但是地图没有出现在屏幕上。我尝试了Places.mapView=Places.mapView.create{}和{{view Places.mapView id=map}{/view}},但是地图没有出现在屏幕上。