I have a function that receives data from a previous JSON response, calls another web service, and adds the results from the second call to the end of the original JSON response. However, the items in my original array get replaced by items in the new array when I used extend. I understand that using $.extend will override my items with identical keys, but I cannot find another option as I am not trying to $.merge my items as I need to concatenate them. Is there any other viable option? Thanks!
//data is the object to which I am trying to add data
function verificaFileServer(data, subprograma, etapa, destino, lista, listaFileServer){
//checking whether some variable has been passed into the function
if(listaFileServer !== undefined){
//SharePoint REST Endpoint
var urlREST = "/_api/lists/getbytitle('File Server')/items?" +
"$select=Title,Link,Modified&$orderby=Modified desc&$filter=IDdoEvento eq " + subprograma + " and EtapaPAS eq '" + etapa + "' and TipodeArquivo eq '" + listaFileServer + "'";
$.ajax({
url: urlREST,
headers: { "Accept": "application/json; odata=verbose"},
success:function(dadosFileServer) {
//trying to add to the end of my original JSON object
$.extend(data.d.results,dadosFileServer.d.results);
//creating a new array containing the original and the new data
dadosConcatenados = data.d.results.sort(function(a, b) {
return (b["Modified"] > a["Modified"]) ? 1 : ((b["Modified"] < a["Modified"]) ? -1 : 0);
});
//calling a function that will build the output based on the concatenated array
montaSaida(dadosConcatenados, subprograma, etapa, lista, destino);
}
});
} else {
//calling a function that will build the output based on the original data
montaSaida(data, subprograma, etapa, lista, destino);
}
}
jsondata , expected finaljsondata ?