0
我一直在尝试几个小时将所有的坐标数组推入一个对象,但我似乎无法找到如何使用角度来查找和推送坐标数组。遍历对象并将其数组推入新对象|中AngularJS
我想我可以使用angular.forEach来完成这个任务,但我无法得到它的工作。我试图找到答案和教程,但似乎没有什么符合我的需要。我可能不完全理解。
这里是我的JSON:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
22.5792379347961,
32.700558883278
]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
22.5794856682809,
34.7005532568414
]
}
}
]
}
这里是我的最新尝试:(甚至更好)
$scope.coordinates = [];
$scope.features = response.data.features;
angular.forEach($scope.features, function(features){
angular.forEach(features.geometry, function(geometry){
$scope.coordinates.push(geometry.coordinates);
});
});
任何教程引用或例子就如何做到这一点,将不胜感激!
我找了如下结果:
"coordinates": [
[22.5792379347961, 32.700558883278],
[22.5794856682809, 34.7005532568414]
]
哎呀,谢谢! :D那就行了。仍然不知道为什么这个工程和我的不是:( – trustkool
几何是不是一个数组,但是一个JSON对象,你可以得到你的财产没有迭代它。如果它已经解决了你的问题,我想你应该接受答案。 。:-) – Sachin