如何循环多维数组 [英] How Do I Loop Multidimensional Array
本文介绍了如何循环多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< script type = text / javascript> ;
var pnr = 863200 ;
$( document )。ready( function (){
$( document )。on(' click',' #search', function (){
// alert('hi');
$ .ajax({
url: http://127.0.0.1/pnrphp/ pnr.php,
类型: POST,
data:' pnrli =' + pnr + ' & action = pnrlist',
dataType: JSON,
成功:函数(响应){
// console.log(response);
// console.log(response ['maindata'] [1] [0]);
$ .each(响应,功能(键,值){
// });
// $('#result')。html('');
// $('#result')。append('Number:'+ response.maindata [0] [0] +'< br />');
});
}
});
});
});
< / script>
怎么样我为每个循环打印下面的mainarray [1] [0]到mainarray [1] [12]。
Object {maindata:Array [2], sum:数组[2],状态:CHART NOT PREPARED}
maindata:数组[2]
0:数组[8]
1:数组[12]
0:乘客1
1:W / L 25,RLGN
2:RAC 42
3:乘客2
4:W / L 26,RLGN
5:RAC 43
6:乘客3
7:W / L 27,RLGN
8:RAC 44
9:乘客4
10: W / L 28,RLGN
11:RAC 45
解决方案
( document )。ready( function (){
( document )。on(' click',跨度> #search', function (){
// alert('hi');
.ajax({
url: http://127.0.0.1/pnrphp/pnr.php,
类型: POST,
data: ' pnrli =' + pnr + ' & ; action = pnrlist',
dataType: JSON,
成功: function (响应){
// console.log(响应);
// console.log(response ['maindata'] [1] [0]);
<script type="text/javascript">
var pnr=863200;
$(document).ready(function() {
$(document).on('click','#search',function(){
//alert('hi');
$.ajax({
url: "http://127.0.0.1/pnrphp/pnr.php",
type: "POST",
data: 'pnrli='+pnr+'&action=pnrlist',
dataType:"JSON",
success: function(response) {
// console.log(response);
//console.log(response['maindata'][1][0]);
$.each(response,function(key,value){
// });
//$('#result').html('');
//$('#result').append('Number: ' + response.maindata[0][0] + '<br />');
} );
}
} );
} );
} );
</script>
How can i print the the below mainarray[1][0] to mainarray[1][12] in for each loop.
Object {maindata: Array[2], sum: Array[2], status: " CHART NOT PREPARED "}
maindata: Array[2]
0: Array[8]
1: Array[12]
0: "Passenger 1"
1: "W/L 25,RLGN "
2: "RAC 42"
3: "Passenger 2"
4: "W/L 26,RLGN "
5: "RAC 43"
6: "Passenger 3"
7: "W/L 27,RLGN "
8: "RAC 44"
9: "Passenger 4"
10: "W/L 28,RLGN "
11: "RAC 45"
解决方案
(document).ready(function() {
(document).on('click','#search',function(){ //alert('hi');
.ajax({ url: "http://127.0.0.1/pnrphp/pnr.php", type: "POST", data: 'pnrli='+pnr+'&action=pnrlist', dataType:"JSON", success: function(response) { // console.log(response); //console.log(response['maindata'][1][0]);
这篇关于如何循环多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文