【发布时间】:2019-11-26 03:47:45
【问题描述】:
每当用户单击父单元格时,我都会尝试显示子表。这是我的代码 sn-p。它仅适用于第二条记录之后的第一行,它没有将数据加载到表中。 (显示纯数据)任何很棒的帮助。谢谢!
<table class="table table-borderless table-hover">
<thead>
<tr>
<th> </th>
<th scope="col">student.Id</th>
.............
</tr>
</thead>
<tbody>
@foreach($data as $student)
<tr class="clickable" data-toggle="collapse" id="row{{ $student['id'] }}" data-target=".row{{ $student['id'] }}">
<td>{{ $student['id'] }}</td>
</tr>
@if ($student['subjects'])
<tr>
<td colspan="3">
<table class="table table-sm table-dark collapse row{{ $student['id'] }}">
<thead>
<tr>
<th scope="col">subject.Id</th>
..............
</tr>
</thead>
<tbody>
@foreach($student['subjects'] as $subject)
<tr>
<td>{{$subject['id']}}</td>
</tr>
@endforeach
</tbody>
</table>
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
【问题讨论】:
-
<tbody>元素的唯一允许的子元素是<tr>元素(请参阅html.spec.whatwg.org/multipage/tables.html#the-tbody-element),因此您现在生成的 HTML 将是无效的。根据您要执行的操作,您可以将该表移动到与学生 ID 相同的<td>中,或者在模板中包含该表的位置添加包装器<tr>。
标签: html asp.net-mvc razor html-table