在数据透视表中显示刀片中的数据

问题描述

我使用如下所示的刀片文件展示了一个名为 it('should fetch data',() => { const actuals: string[] = []; // commented version doesn't work // component.symbol$.subscribe((symbol) => { actuals.push(symbol); } ; component.symbol$.subscribe({ next(symbol) { actuals.push(symbol); },}); expect(actuals).toEqual(['']); component.symbol = 'IBM'; component.ngOnChanges(); expect(actuals).toEqual(['','IBM']); }); 的数据透视表:

enter image description here

但我想这样展示,怎么办?

没有 姓名 俯卧撑 坐起来 备份 蹲跳
1. 基思·克里斯特博士 20 10 12 23
2. 贾伦·文施 34 13 24 53

这是我用来展示桌子的刀片:

community_competition

<thead> <tr> <th scope="col">#</th> <th scope="col">name</th> <th scope="col">push up</th> <th scope="col">sit up</th> <th scope="col">back up</th> <th scope="col">squat jump</th> </tr> </thead> <tbody> @PHP $no = 1; @endPHP @foreach ($data as $v) <tr> <th scope="row">{{ $no++ }}</th> <td>{{ $v->community->name}}</td> <td>{{ $v->point}}</td> </tr> @endforeach </tbody> 模型:

CommunityCompetition

public function community() { return $this->belongsTo(Community::class); } public function competition() { return $this->belongsTo(Competition::class); } 控制器:

CommunityCompetition

public function index() { $data = CommunityCompetition::with(['community','competition'])->get(); return view('cms.rank.index',compact('data')); } 表:

community
id 姓名
1 基思·克里斯特博士
2 贾伦·文施

$table->id(); $table->string('name',100); 表:

competition
id 姓名
1 俯卧撑
2 坐起来
3 备份
4 蹲跳

$table->id(); $table->string('name',100); 表:

community_competition
id community_id competition_id
1 1 1 20
2 1 2 10
3 1 3 12
4 1 4 23
5 2 1 34
6 2 2 13
7 2 3 24
8 2 4 53

解决方法

好吧,您的表有 6 列,而您仅使用此代码填充了 3 列:

<tr>
    <th scope="row">{{ $no++ }}</th>
    <td>{{ $v->community->name}}</td>
    <td>{{ $v->point}}</td>
</tr>

因此,您需要再添加 3 个 td 以完成其他的。我不知道名称是什么,因为您的 community_competition 不存储这 3 个缺失的列。

你应该得到这样的结果(记住你必须使用正确的模型和属性):

<tr>
    <th scope="row">{{ $no++ }}</th>
    <td>{{ $v->community->name}}</td>
    <td>{{ $v->point}}</td>
    <td>{{ $v->sit_up }}</td>
    <td>{{ $v->back_up }}</td>
    <td>{{ $v->squat_jump }}</td>
</tr>