javascript - 我如何在 Angular JS 谷歌地图中传递嵌套的 json 数组对象

标签 javascript json angularjs

我是 Angular js 新手。我正在尝试将我的 json lat lon 数据传递到 goole api 。我的 json 文件结构

{
 "totalCount":206,
  "deals":[{
       "id":"2",
       "Name":"samir",
       "locations":[{
         "location":"Mundhwa Gaon",
         "address":"Mundhwa Gaon, North Main Road, Pune - 411 001",
          "latLon":"18.53918870,73.90790910"
          },
          "location":"Mundhwa Gaon",
          "address":"Mundhwa Gaon, North Main Road, Pune - 411 001",
          "latLon":"18.53918870,73.90790910"
          },
        ]

   }]
}

我的 Angular js代码

$http({method: 'GET', url: '/api/v1/asas}).success(function(data) {             
            $scope.deal = data.deals;               
            if(data.deals.hasOwnProperty("locations") && data.deals.locations!=null){           

                var location=$scope.deal.locations[0]['latLon'];
                var locationlatlong=location.split(",");
                $scope.map = {center: {latitude: locationlatlong[0], longitude: locationlatlong[1] }, zoom: 4 }
                $scope.options = {scrollwheel: false};
                var markers = [];
                for (var i = 0; i < $scope.deal.locations.length; i++) {
                    markers.push(createmarker(i, $scope.deal.locations[i]['location'], $scope.deal.locations[i]['latLon'],$scope.deal.locations[i]['address']))
                }
                $scope.markers = markers;
                if(badBrowser){
                    $scope.rendermap=false; 

                }else{                      
                    $scope.rendermap=true;      

                }
            }                               
        });

但是我的 if 条件不起作用,因为它们没有获得值(value)。我正在使用 Angular js 1.2.23

最佳答案

deals 是一个数组,其中数组的每个元素都是一个包含一笔交易字段的对象,您应该对 data.deals[i] 使用循环访问第 i 笔交易的数据。

关于javascript - 我如何在 Angular JS 谷歌地图中传递嵌套的 json 数组对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25904398/

相关文章:

javascript - 如何使用 promise 链接 Mongoose 查询?

javascript - SCRIPT5007 : The value of the property onclick ="JavaScript:functionName(' name', '2' 、 '0' ) 为 null 或未定义,不是 Function 对象(ie8)

javascript - 仅在滚动时保持固定 div 并取决于父 div 高度

javascript - AngularJs 将 HTML 中每个 ng-repeat 的实例传递给指令

javascript - 将数组作为指令参数传递

javascript - 如果单元格为空,则在此单元格中插入 0

javascript - 似乎无法在页面加载时滚动到 div 的底部(angularJS)

android - 用gson拯救模型的公共(public)结构

c# - 反序列化从 node.js (azure sdk) 发送的 Azure ServiceBus 队列消息时出错

python - 如何使 json-schema 允许一个字段而不是另一个字段?