我有两个网络服务:
[ { "id": "1","headline": "some text","body": "some text","authorId": "2" },{ "id": "2","authorId": "1" } ]
{ "id": "1","name": "Test Name","email": "[email protected]","photo": "path/to/img" }
我想将两者结合起来,这样我就可以在文章概览列表中显示作者姓名和照片.
像这样:
[ { "id": "1","authorId": "2","author_info": { "id": "2","name": "Another Test Name","email": "[email protected]","photo": "path/to/img" } },"authorId": "1" "author_info": { "id": "1","photo": "path/to/img" } } ]
我有一个“文章”服务来获取文章,但是在返回“文章”服务输出之前,使用来自类似“作者”服务的作者信息来丰富返回的JSON的最佳方法是什么?
factory('Authors',['$http',function($http){ var Authors = { data: {},get: function(id){ return $http.get('/api/authors/' + id + '.json') .success(function(data) { Authors.data = data; }) .error(function() { return {}; }); } }; return Authors; }]). factory('Articles','Authors',function($http,Authors){ var Articles = { data: {},query: function(){ return $http.get('/api/articles.json') .success(function(result) { Articles.data = result; // How to get the author info into this JSON object??? }) .error(function() { Articles.data = []; }); } }; return Articles; }])
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。