0
App.MapView = App.ChartView.extend({
data: undefined,
dataLoaded: NO,
markersArray: undefined,
finishloadingdata: function (rawdata) {
var latitude, longitude;
var array = new Array();
$(rawdata).find("Book").each(function() {
$(this).find("Location");
latitude = $(this).find("Latitude").text();
longitude = $(this).find("Longitude").text();
array.push(new Array(latitude, longitude));
});
this.set('markersArray', array);
this.set('data', rawdata);
this.set('dataLoaded', YES);
},
optionsView: SC.View.extend({
layout: {
left: 0,
top: 0,
right: 0,
bottom: 50
},
map: null,
center: new google.maps.LatLng(46.48, 7.9),
zoom: 14,
array: this.get('markersArray'),
didCreateMap: null,
render: function (ctx, first) {
if (first) {
ctx.push('<div style="position:absolute;top:0;left:0;right:0;bottom:0;"></div>');
}
},
didCreateLayer: function() {
this.invokeLast('_createMap');
},
_createMap: function() {
if (this._map) {
google.maps.event.trigger(this._map, 'resize');
} else {
var center = this.get('center');
var opts = {
zoom: this.get('zoom'),
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var div = this.$('div')[0];
var map = new google.maps.Map(div, opts);
this._map = map;
this.set('map', map);
//i want to make an array of markers
if (this.didCreateMap) this.didCreateMap(map);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(46.48, 7.9),
map: map
});
}
}
MapView是一個擴展ChartView的視圖,我重寫了optionsView以使其顯示谷歌地圖。它工作得很好,我只想把標記放在地圖上,座標從xml文件中檢索。我得到的數組很好。 我的問題是,當我想給選項查看該數組的值,它給我的錯誤:對象[對象窗口]沒有方法'得到'。從sproutcore的父視圖中獲取數組
我該如何給optionsView的數組屬性設置markersArray的值,以便我可以使用它將標記放在我的地圖上。
非常感謝!
非常感謝您的幫助! – Elie 2012-07-26 08:34:48
@Elie沒問題!很高興能成爲服務對象:-) – 2012-07-27 17:22:58