///Returning JSON 1
$http.get("url1").
then(function (response) {
$scope.foo = response.data;
});
///Returning JSON 2
$http.get("url2").
then(function (response) {
$scope.foo = response.data;
});
///Returning JSON (n)
$http.get("n").
then(function (response) {
$scope.foo = response.data;
});
我能以某种方式将这些 JSON 对象连接成一个吗?原因是我有很多数据,而且我宁愿显示大量数据供用户过滤,也不愿让他们点击 SPA 中的 1000 个页面,如果可能的话,我想加入他们(在当然是合理的方式)。
编辑
我是这样想的
var url ="";
for (... i < 100...) {
url = "http://url.com"+i+"";
$http.get(url).
then(function(response){
$scope.foo.concat(response.data);
}
);
}
更新
我已经设法将返回的 JSON 加入到一个对象数组中。但问题是这个数组现在包含的对象本身包含一个对象,而这个对象本身又包含一个对象数组……是的!
最佳答案
如果它是数组那么你可以连接它。
先初始化空数组
$scope.foo = [];
$http.get("url1").
then(function (response) {
$scope.foo.concat(response.data);
});
关于angularjs - 如何使用嵌套资源连接来自不同 URL 的 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42836328/