0
我在后面的骨干视图中遇到了一个问题,呈现谷歌街景。街景和骨干变量范围
问题是,在processSVData函数中,this
不是App.DetailStreetView
的实例。当我console.log(this)
里面processSVData()
,我得到DOMWindow
对象。因此,试图访问this.panorama
当我undefined
App.DetailStreetView = Backbone.View.extend({
initialize: function() {
this.latLng = new google.maps.LatLng(37.869085,-122.254775);
this.panorama = new google.maps.StreetViewPanorama(this.el);
},
render: function() {
var sv = new google.maps.StreetViewService();
sv.getPanoramaByLocation(this.latLng, 50, this.processSVData);
},
processSVData: function(data, status) {
if (status == google.maps.StreetViewStatus.OK) {
// calculate correct heading for POV
//var heading = google.maps.geometry.spherical.computeHeading(data.location.latLng, this.latLng);
this.panorama.setPano(data.location.pano);
this.panorama.setPov({
heading: 270,
pitch:0,
zoom:1,
});
this.panorama.setVisible(true);
}
},
});
最好的解决方案,因为你已经在页面上有下划线。尽可能使用本地绑定。 – adrian
@ amchang87:下划线的'_.bindAll'建立在'_.bind'上,并且AFAIK,'_.bind'使用本地的'Function.bind'(如果可用)。 –