我需要與2個JSON對象數組一起工作,是否有可能將兩個數組放在同一個循環中,使用& &分隔符,還是每個都在每個循環內?我可以在每個AJAX循環中放2個數組嗎?
我需要在同一個循環中使用2個數組,這怎麼可能?
這是PHP的頁面我的JSON:
function loadBlocSite() {
//Création d'un tableau
$currentArrayData = array();
//Remplissage du tableau
$currentArrayData['configAlm'] = array(
array('blocName' => 'blockAlarmeContent', 'blocLVTwoName' => 'boxLV2Content', 'blocHeader' => 'ALARME', 'label' => 'Criticité', 'id' => 'almCrit', 'ico' => '', 'refreshFreq' => '2', 'TNT' => '2', 'FM' => '2'),
array('blocName' => 'blockAlarmeContent', 'blocLVTwoName' => 'boxLV2Content', 'blocHeader' => 'ALARME', 'label' => 'Sans supervision', 'id' => 'almSansSup', 'ico' => '', 'refreshFreq' => '2', 'TNT' => '2', 'FM' => '2'),
array('blocName' => 'blockAlarmeContent', 'blocLVTwoName' => 'boxLV2Content', 'blocHeader' => 'ALARME', 'label' => 'Non nominale', 'id' => 'almNonNom', 'ico' => '', 'refreshFreq' => '2', 'TNT' => '2', 'FM' => '2')
);
$currentArrayData['configSite'] = array(
array('blocName' => 'blockSitesContent', 'blocLVTwoName' => 'boxLV2Content', 'blocHeader' => 'ALARME', 'label' => '-3dB', 'id' => 'steMoins3db', 'ico' => '', 'refreshFreq' => '2', 'TNT' => '4', 'FM' => '1'),
array('blocName' => 'blockSitesContent', 'blocLVTwoName' => 'boxLV2Content', 'blocHeader' => 'ALARME', 'label' => 'Rx', 'id' => 'steRx', 'ico' => '', 'refreshFreq' => '2', 'TNT' => '4', 'FM' => '1'),
array('blocName' => 'blockSitesContent', 'blocLVTwoName' => 'boxLV2Content', 'blocHeader' => 'ALARME', 'label' => 'Perte HF', 'id' => 'stePerteHF', 'ico' => '', 'refreshFreq' => '2', 'TNT' => '4', 'FM' => '1'),
array('blocName' => 'blockSitesContent', 'blocLVTwoName' => 'boxLV2Content', 'blocHeader' => 'ALARME', 'label' => 'Décrochage HS', 'id' => 'steDecrochHS', 'ico' => '', 'refreshFreq' => '2', 'TNT' => '4', 'FM' => '1'),
// array (
// array('blocName' => 'blockSitesContent', 'label' => 'GE Actif En cours', 'id' => 'steGEEnCours', 'ico' => '', 'refreshFreq' => '2', 'val' => '2'),
// array('blocName' => 'blockSitesContent', 'label' => 'GE Actif -10 jrs', 'id' => 'steGEMoins10jrs', 'ico' => '', 'refreshFreq' => '2', 'val' => '2')
//);
);
return $currentArrayData;
}
這裏是我的代碼:
$.ajax({
url: 'Pages/index.php', //ou il y a le traitement json
type: 'get',
dataType: 'json',
data: 'action=loadBlocSite',
success:function(data){
$.each(arrayOfData['configAlm'], function(currentIdx, currentValue){
$.each(arrayOfData['configsite'], function(currentIdx, currentValue){
if(currentValue.id == "almCrit"){
$("#almCrit").click(function() {
$('#mainViewContainer').animate({'left': '-30rem'}, 250, function(){
$('#boxLV2Content').empty();
var criticiteContent = '';
criticiteContent += '<div class="tableHeader">';
criticiteContent += '<div class="tableCell_title">TNT</div>';
criticiteContent += '<div class="tableCell_title">FM</div>';
criticiteContent += '</div>';
criticiteContent += '<div class="lineBloc">';
criticiteContent += '<img class="lineBlocIco" src="'+ currentValue.ico +'">';
criticiteContent += '<div class="lineBlocTitle">'+ currentValue.label +'</div>';
criticiteContent += '<div class="lineBlocValue">'+ currentValue.TNT +'</div>';
criticiteContent += '<div class="lineBlocValue">'+ currentValue.FM +'</div>';
criticiteContent += '</div>';
console.log(currentValue.blocName);
$("#" + currentValue.blocLVTwoName).append(criticiteContent);
});
});
} else return 'this is not almCrit Id';
});
});
}
});
僅僅只要兩個數組,當它們在兩個數組中的相同索引處時,它們是否屬於一起?你並沒有真正地解釋這兩個數組是如何連接的,你的代碼顯然只能看到在內部循環中聲明的'currentValue',由於外部循環而多次重複同樣的事情。例如,'ico'是第一個還是第二個數組對象的屬性?請爲該輸入提供樣本輸入和所需的輸出。 – trincot
這裏是ajax嗎? – Hitmands
@Hitmands我只是apdated我的帖子阿賈克斯調用 – Zee