I'm using a REST server to retrieve data. In the AngularJS UI the user is given the choice of a few options to create a query to send to the REST server. The problem is the server only accepts one of each, so if user wants to search for multiple Entities, they can't. I'm trying to think of a way to send off multiple requests (quantity of requests depends on length of Entity array, which is set by the user in UI). So far all I can think of is for loop by the length of the entity array, and for each loop send a request - my problem is how do I join these two sets of data? Each time the for loop completes the data is overridden with the next set it's sent off for. And the amount of times the requests are sent is totally dependent on the amount of entities the user needs returned.
1 Answer
If you have any unique identifier for each result item then you can try the following algorithm. Hopefully It will solve the issue.
var data = [];
loop through options selected by user {
request sent {
on sucess() {
loop though RESPONSE_DATA_ARRAY {
var id = RESPONSE_DATA_ARRAY_ITEM.uniuqe_key
if(data[id] === undefined){
data[id] = RESPONSE_DATA_ARRAY_ITEM;
//Stored as Key Value pair, which will help to identify same object each time easily.
}
}
}
}
}
1 Comment
notAChance
Thanks, I will try to implement this and get back :D
entitiesuser chooses, could be 2 requests, could be 10.