Angularjs 您将如何组织接收2个JSON文件?

Angularjs 您将如何组织接收2个JSON文件?,angularjs,json,Angularjs,Json,我很好奇如何使用Angular和JSON API最好地组织数据。我的项目的目标是获取第一个文件并将其推送到一个数组中,然后使用其中一个键值,它根据我发送回来的值请求第二个JSON文件。然后我可以基于这个最终返回在数组上重复(例如) 以下是我目前的代码: app.factory('mtnFactory', ['$http', function($http){ return { getMtns : function(){ return $http.ge

我很好奇如何使用Angular和JSON API最好地组织数据。我的项目的目标是获取第一个文件并将其推送到一个数组中,然后使用其中一个键值,它根据我发送回来的值请求第二个JSON文件。然后我可以基于这个最终返回在数组上重复(例如)

以下是我目前的代码:

app.factory('mtnFactory', ['$http', function($http){
  return {
          getMtns : function(){
            return $http.get('/js/mtnData.json');
          },
          getWeather: function(zipcode){
            return http.get('http://api.wunderground.com/api/**KEY**/conditions/forecast/settings/q/'+zipcode+'.json')
    }
  }
}]);

app.controller('apresController', ['$scope', 'mtnFactory', function($scope, mtnFactory){

    $scope.mtnData = []
    var mtnPull = function(response){
        response.data.forEach(function(item){
            mtnFactory.getWeather(item.zip).then(weatherPull)
            $scope.mtnData.push(item)
        })
    }
    mtnFactory.getMtns().then(mtnPull)

    $scope.weatherData = []
    var weatherPull = function(response){
            $scope.weatherData.push(response.data)
    }
这里的关键是,因为我想使用的“名称”在$scope.mtnda中,但我需要的重要信息在$scope.weatherData中,我不知道如何在2个不同的$scope中重复

那么,如何组织这些信息以方便访问,或者我应该将所有信息都放入一个数组中呢


我很欣赏您的输入。

使用单个json数组而不是两个不同的json数组的最佳方式。并使用angularjs过滤器从数组中单独获取所选json对象列表。比如说

$scope.mtnData = []
var mtnPull = function(response){
    response.data.forEach(function(item){
        mtnFactory.getWeather(item.zip).then(weatherPull)
        $scope.mtnData.push(item)
    })
}
// Now consider $scope.mtnData is merged array with both datas
$Scope.weatherData = _.filter($scope.mtnData , function(data){ return mtnData.zipcode == zipcode});