我正在尝试将3个json响应$ scope.auditorium,$ scope.hotels和$ scope.exhibitions合并为一个,这可能吗?帮助将不胜感激!甚至更好的是,如果我能够创建一个搜索功能,该功能能够搜索全部3个并显示搜索结果
代码:
myApp.controller('displayCatController', ['$scope','$http', function($scope, $http){
//Display auditoriums information
$http({
method: 'GET',
url:'url'
}).then(function successCallback(response) {
$scope.auditoriums = response.data.SrchResults;
$scope.auditoriums.splice(0,1);
}, function errorCallback(response) {
console.log(response);
});
//Display exhibitions information
$http({
method: 'GET',
url: 'url'
}).then(function successCallback(response) {
$scope.exhibitions = response.data.SrchResults;
$scope.exhibitions.splice(0,1);
}, function errorCallback(response) {
console.log(response);
});
//Display hotels information
$http({
method: 'GET',
url: ''
}).then(function successCallback(response) {
$scope.hotels = response.data.SrchResults;
$scope.hotels.splice(0,1);
}, function errorCallback(response) {
console.log(response);
});
}]);
答案 0 :(得分:1)
您可以使用Promise.all([... promiseObject]) 示例:
Promise.all([
$http(...),
$http(...),
]).then(function(data) {
// data is merge array of response 1 and response 2
})