2013-10-15 30 views
0

我是Angular的新手,所以我需要一些帮助,以便如何在markers.venues中推送物品。推送物品//角单张

我的代码是:

var app = angular.module("basicMapApp", ["leaflet-directive"]); 
app.controller("CenterController", 
    [ '$scope', function($scope) { 
     angular.extend($scope, { 
      defaults: { 
       tileLayer: "https://dnv9my2eseobd.cloudfront.net/v3/foursquare.map-ikj05elx/{z}/{x}/{y}.png", 
       maxZoom: 14, 
       minZoom: 3, 
      }, 
      center: { 
       lat: 52.38, 
       lng: 4.8777, 
       zoom: 6 
      }, 
      markers: { 
       venues: { 
        Madrid: { 
         lat: 52.38, 
         lng: 4.8777, 
         message: "This is Madrid. But you can drag me to another position", 
         focus: false, 
         draggable: true 
        }, 
        Barcelona: { 
         lat: 52.38, 
         lng: 5.8777, 
         message: "This is Barcelona. You can't drag me", 
         focus: false, 
         draggable: false 
        } 
       } 
      } 
     }); 

    }] 
); 

我如何在JavaScript中的markers.venues添加一个新的项目?

例如我试过,但没有奏效:

$scope.markers.venues.push({ 
    Amsterdam: { 
       lat: 52.38, 
       lng: 5.9777, 
       message: "This is Amsterdam. You can't drag me", 
       focus: false, 
       draggable: false 
       } 
    }); 

角小叶记录here

+1

'$ scope.markers.venues'不是一个数组,所以推不会工作。试试:'$ scope.markers.venues ['阿姆斯特丹'] = {/*...*/}' – Yoshi

+0

@Yoshi现货上,感谢结构公告。 – Diolor

回答

0

试试这个

$scope..markers.venues['Amsterdam']={ 
      lat: 52.38, 
      lng: 5.9777, 
      message: "This is Amsterdam. You can't drag me", 
      focus: false, 
      draggable: false 
      } 
+0

谢谢。在'$ scope'之后加一个'.'。 :) – Diolor

+0

WC :)是的,那是错误的.. –