मैं दो वेब सेवाओं है संयोजन AngularJSवेब सेवा प्रतिक्रियाओं
[
{
"id": "1",
"headline": "some text",
"body": "some text",
"authorId": "2"
},
{
"id": "2",
"headline": "some text",
"body": "some text",
"authorId": "1"
}
]
और एक दूसरे को देता है एक इस तरह "लेखक", एक आईडी दिया:
{
"id": "1",
"name": "Test Name",
"email": "[email protected]",
"photo": "path/to/img"
}
मैं दोनों को गठबंधन करना चाहता हूं, इसलिए मैं एक लेख अवलोकन सूची में लेखकों का नाम और फोटो प्रदर्शित कर सकता हूं।
इस तरह:
[
{
"id": "1",
"headline": "some text",
"body": "some text",
"authorId": "2",
"author_info": {
"id": "2",
"name": "Another Test Name",
"email": "[email protected]",
"photo": "path/to/img"
}
},
{
"id": "2",
"headline": "some text",
"body": "some text",
"authorId": "1"
"author_info": {
"id": "1",
"name": "Test Name",
"email": "[email protected]",
"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', ['$http', '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;
}])
कृपया मुझे यह भी बताएं कि यह एक पूरी तरह से गलत दृष्टिकोण है या नहीं। :)
सलाह के लिए धन्यवाद, लेकिन यह, सही हर लेख पर सभी लेखकों को लाते समय का मतलब होगा? यह बहुत अधिक यातायात है। –
नहीं, कोड मानता है कि आप सभी लेख प्राप्त कर सकते हैं और पूरा होने पर आप सभी लेखकों को लाएंगे। फिर परिणामों को गठबंधन करें। केवल दो अनुरोध शामिल हैं – Ulises
@ JakobLøkkeMadsen क्या आप इसे समझते हैं? – Ulises