ajax – 结合Web服务响应的AngularJS
发布时间:2020-12-16 02:53:43 所属栏目:百科 来源:网络整理
导读:我有两个网络服务: 一个人返回“文章”,如下所示: [ { "id": "1","headline": "some text","body": "some text","authorId": "2" },{ "id": "2","authorId": "1" }] 另一个返回像这样的“作者”,给出一个id: { "id": "1","name": "Test Name","email": "t
我有两个网络服务:
一个人返回“文章”,如下所示: [ { "id": "1","headline": "some text","body": "some text","authorId": "2" },{ "id": "2","authorId": "1" } ] 另一个返回像这样的“作者”,给出一个id: { "id": "1","name": "Test Name","email": "test@test.com","photo": "path/to/img" } 我想将两者结合起来,这样我就可以在文章概览列表中显示作者姓名和照片. 像这样: [ { "id": "1","authorId": "2","author_info": { "id": "2","name": "Another Test Name","email": "test2@test.com","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; }]) 如果这是一个完全错误的方法,请告诉我. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ruby-on-rails – 内联HAML链接,但内容很多
- objective-c – 从我在Facebook的应用程序发布
- c# – WPF无法访问嵌套控件
- 如何在使用FreeRTOS时保持代码的可移植性
- Cocos2d-x 3.x 无法打开包含文件extensions/ExtensionExpor
- 通过history解决ajax不支持前进/后退/刷新的问题
- Oracle 12c 多租户家族(12c 18c 19c) 如何在 PDB 中添加
- c# – 最优雅的方式检查查询字符串参数的值,如果不为null?
- PostgresQL数据库的参数需要KeepAlive和防火墙清理检查的时
- Flex4 Spark Container