ループ内の現在の ID に基づいて temp.json の値を取得する方法に苦労しています。以下のコードを参照してください.json. そしてそれらをテーブルに出力します。temp.json の内容は常に変化します。
配達.json
{
"all_info":[
{
"deliveryid":"1",
"deldescription":"Food Delivery3432",
"delivery_create_time":"2013-09-26 01:19:03",
"routeid":"1",
"startloc":"Newcastle",
"endloc":"Paris",
"distance":"500",
"stockid":"2",
"stockname":"Chicken",
"stockshelf":"20",
"stockdesc":"Newcastle Chickens",
"supplierid":"1",
"supname":"Benny's Fresh Food",
"supaddress":"1 Osborne Road",
"supcity":"Manchester",
"suppostcode":"MA11KL7",
"vehicleid":"1",
"vehiclereg":"TRE12XYZ"
},
{
"deliveryid":"2",
"deldescription":"Fresh Beef",
"delivery_create_time":"2013-09-26 01:19:03",
"routeid":"3",
"startloc":"London",
"endloc":"Niece",
"distance":"800",
"stockid":"1",
"stockname":"Beef",
"stockshelf":"20",
"stockdesc":"Beef from Madrid Farm",
"supplierid":"2",
"supname":"Denone Ltd",
"supaddress":"231 Morje Road",
"supcity":"Barcelona",
"suppostcode":"MR3K12",
"vehicleid":"2",
"vehiclereg":"RFGXMN4"
},
{
"deliveryid":"3",
"deldescription":"Meat Delivery",
"delivery_create_time":"2013-10-14 01:48:59",
"routeid":"3",
"startloc":"London",
"endloc":"Niece",
"distance":"800",
"stockid":"4",
"stockname":"Trout and Salmon",
"stockshelf":"11",
"stockdesc":"FIshers Best Catch",
"supplierid":"4",
"supname":"Youngs Ltd",
"supaddress":"4 Tressle Road",
"supcity":"Telford",
"suppostcode":"TE62GF5",
"vehicleid":"1",
"vehiclereg":"TRE12XYZ"
},
{
"deliveryid":"6",
"deldescription":"Travel Chicken",
"delivery_create_time":"2013-10-16 02:27:26",
"routeid":"4",
"startloc":"Edingburgh",
"endloc":"Malaga",
"distance":"2000",
"stockid":"3",
"stockname":"Rare Meats",
"stockshelf":"45",
"stockdesc":"Expensive Food",
"supplierid":"3",
"supname":"Posh Food Ltd",
"supaddress":"3 Fawn Street",
"supcity":"Warick",
"suppostcode":"WR32B54",
"vehicleid":"1",
"vehiclereg":"TRE12XYZ"
}
]
}
temp.json
{
"temp_info":[
{
"temperatureid":"1",
"recorded_temp":"24",
"weather":"Sunny",
"temp_recorded_time":"2013-09-27 20:54:11",
"temp_deliveryid":"1"
},
{
"temperatureid":"2",
"recorded_temp":"14",
"weather":"Cloudy",
"temp_recorded_time":"2013-09-27 20:54:11",
"temp_deliveryid":"3"
},
{
"temperatureid":"3",
"recorded_temp":"17",
"weather":"Rain",
"temp_recorded_time":"2013-09-27 20:54:51",
"temp_deliveryid":"2"
},
{
"temperatureid":"4",
"recorded_temp":"32",
"weather":"Hot",
"temp_recorded_time":"2013-09-27 20:54:51",
"temp_deliveryid":"1"
}
]
}
ウェブサイトのコード例
$.getJSON("jsonfiles/deliveries.json", function(delivery) {
for(var i = 0; i < delivery.all_info.length; i++) {
var deliv = delivery.all_info[i];
x = '<div id="' + deliv.deliveryid + '">' + deliv.deldescription + '</div>
document.getElementById("sortable1").innerHTML += x;
$.getJSON("jsonfiles/temp.json", function(temp) {
deliv.forEach(function(entry) {
var tempi = tempe.temp_info[i];
if (tempi.temp_deliveryid == entry.deliveryid){
var y = '<tr><td>[' + temp.temp_recorded_time + '] '+ temp.temperature_id + ' - Temperature: ' + temp.recorded_temp +'℃ - Weather (' + temp.weather + ')!</td></tr>';
document.getElementById("temptbody").innerHTML += y;
});
}
});
});