How might one implement a callback function with multiple sources and then access an array for example, like JSONP?
//website names or API variables to add to callbacks
var callbacks = $.Callbacks();
callbacks.add(result);
//then get the callback.result[i] something like this pseudocode...?
//get API1, API2, API3 then process each API and JSON code one at a time with the callback object.
Trying to get this code block to load three API in the result callback
var listAPIs = "";
var darkForecastAPI = [];
var result = [];
$.each(numDaysAPITimes, function(a, time) {
var darkForecastAPI= /*"http://ift.tt/1eU3pXU" + currentAPIKey + "/history_" + time + "/q/" + state + "/" + city +".json?callback=?"; */
"http://ift.tt/1JmMFqC" + currentAPIKey + "/" + city + time + "?callback=?";
//http://ift.tt/1iYC1hI
var JSONAPIS = $.getJSON(darkForecastAPI, {
tags: "WxAPI[" + i + "]", //Is this tag the name of each JSON page? I tried to index it incase this is how to refer to the JSON formatted code from the APIs.
tagmode: "any",
format: "json"
},
$.when.apply(JSONAPIS).then(function(results) { /*no log simply an array */
var eachPrecipSum = 0.0;
var totalPrecipSinceDate = 0.0;
for(var c = 0; c <= result.daily.data.length-1; c++)
{
if(result.daily.data[c].precipIntensity >= 0.0000 && result.daily.data[c].precipType == "rain") /*Number(result.history.dailysummary.precipm, result.history.dailysummary.rain*/
{
eachPrecipSum = result.daily.data[c].precipIntensity;
totalPrecipSinceDate = eachPrecipSum + totalPrecipSinceDate; ///Write mean precip
alert( Math.round(eachPrecipSum * 10000)/10000);
$("body").append("p").text("There has been as least a total of "+ Math.round(totalPrecipSinceDate * 10000)/10000 + " inches per hour of rain at the location in the last " + userDataDatePick + " days")
}
Aucun commentaire:
Enregistrer un commentaire