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をオーバーライドしてGoogleマップを表示します。それは問題なく動作します。xmlファイルから取得した座標を使用して、そのマップにマーカーを配置したいだけです。配列は問題なく取得できます。私の問題は、optionsViewにその配列の値を指定したい場合に、エラーが発生することです。 オブジェクト[オブジェクトウィンドウ]にはメソッド'get'がありません

optionsViewのarrayプロパティにmarkersArrayの値を指定して、それを使用してマーカーをマップに配置するにはどうすればよいですか。

どうもありがとう!!

4

1 に答える 1

0

それ以外の

array: this.get('markersArray')

あなたはおそらくやりたい

arrayBinding: 'parentView.markersArray'

これはSproutCoreのバインディング機能を使用し、arrayプロパティが常に親ビューのプロパティを指すようにしmarkersArrayます。optionsViewただし、チャートビューの上部に以下を追加して、それが親の子であることを指定する必要がある場合もあります。

App.MapView = App.ChartView.extend({
  childViews: ['optionsView'],
  ...

お役に立てれば!この問題について他にご不明な点がありましたら、コメントを追加してください。サポートさせていただきます。

于 2012-07-25T18:36:06.383 に答える