繁体   English   中英

从数组创建 Laravel 刀片水平表视图

[英]Create laravel blade horizontal table view from array

我有一个 Laravel DB::Query 给我这样的结果

 arrayResult = array('nip' => '12345678', 'nama' => 'rachmat', 'month' => '1', 'sum' => 13'),
               array('nip' => '12345678', 'nama' => 'rachmat', 'month' => '3', 'sum' => 10'),
               array('nip' => '12345678', 'nama' => 'rachmat', 'month' => '8', 'sum' => 9'));

然后我像这样创建多维数组

foreach ($pegawai as $key ) {
            $peg[$key->nip]['nama'] = $key->nama;
            $peg[$key->nip]['nip'] = $key->nip;
            $peg[$key->nip]['month'][$key->month] = $key->sum;

        }

数组的结果是这样的

array(12345678
    ('nama' => 'Rachmat', 
     'nip' => '12345678', 
     Month(1 => 13,
           3 => 10,
           8 => 9)));

然后我在刀片表中查看它,如下所示:

@foreach($peg as $st)
   <tr>
       <td style="text-align: center;">{{$no++}}</td>
       <td>{{$st['nama']}}<br>{{$st['nip']}}</td>    
       @foreach($st['bulan'] as $a => $value)     
       <td style="text-align: center;"> {{ $value }}   </td>
       @endforeach
       </tr>
@endforeach

问题是 $value 数据按顺序显示,而不是按照数据的月份。

我的观点:

 <table id="table" class="table table-striped table-bordered table-hover" > <thead> <tr class="tableheader"> <th style="width:10px" rowspan="2" style="text-align: center; vertical-align: middle;">#</th> <th rowspan="2" style="text-align: center; vertical-align: middle;">Nama Pegawai</th> <th colspan="12" style="text-align: center;">Bulan</th> </tr> <tr> <th style="text-align: center;">January</th> <th style="text-align: center;">February</th> <th style="text-align: center;">March</th> <th style="text-align: center;">April</th> <th style="text-align: center;">May</th> <th style="text-align: center;">June</th> <th style="text-align: center;">July</th> <th style="text-align: center;">August</th> <th style="text-align: center;">Sept</th> <th style="text-align: center;">Okt</th> <th style="text-align: center;">Nop</th> <th style="text-align: center;">Dec</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">1</td> <td>Rachmat<br>123456</td> <td style="text-align: center;"> 13 </td> <td style="text-align: center;"> 10 </td> <td style="text-align: center;"> 9 </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> </tr> </tbody> </table>

我想要什么:

 <table id="table" class="table table-striped table-bordered table-hover" > <thead> <tr class="tableheader"> <th style="width:10px" rowspan="2" style="text-align: center; vertical-align: middle;">#</th> <th rowspan="2" style="text-align: center; vertical-align: middle;">Nama Pegawai</th> <th colspan="12" style="text-align: center;">Bulan</th> </tr> <tr> <th style="text-align: center;">January</th> <th style="text-align: center;">February</th> <th style="text-align: center;">March</th> <th style="text-align: center;">April</th> <th style="text-align: center;">May</th> <th style="text-align: center;">June</th> <th style="text-align: center;">July</th> <th style="text-align: center;">August</th> <th style="text-align: center;">Sept</th> <th style="text-align: center;">Okt</th> <th style="text-align: center;">Nop</th> <th style="text-align: center;">Dec</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">1</td> <td>Rachmat<br>123456</td> <td style="text-align: center;"> 13 </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> 10 </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> </td> <td style="text-align: center;"> 9 </td> </tr> </tbody> </table>

所有帮助appriciated

试试这个

@foreach($peg as $st)
   <tr>
       <td style="text-align: center;">{{$no++}}</td>
       <td>{{$st['nama']}}<br>{{$st['nip']}}</td>  

       @for($i = 1, $i <= 12, $i++)
          <td style="text-align: center;"> {{ isset($st['month'][$i]) ? $st['month'][$i] : "" }}   </td>
       @endfor

   </tr>
 @endforeach

如何在 vue js 上转换它?

 @foreach($peg as $st)
   <tr>
       <td style="text-align: center;">{{$no++}}</td>
       <td>{{$st['nama']}}<br>{{$st['nip']}}</td>  

       @for($i = 1, $i <= 12, $i++)
          <td style="text-align: center;"> {{ isset($st['month'][$i]) ? $st['month'][$i] : "" }}   </td>
       @endfor

   </tr>
 @endforeach

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM