按下按钮时弹出一个模态。问题是,如何将值传递给模态?
我的表格如下图所示。正如您所看到的,每行都有不同的ID。我想在按下按钮
后获取特定行的ID我的代码:
import threading
import time
# Lock to serialize console output
output = threading.Lock()
def threadfunc(a,b):
for i in range(a,b):
time.sleep(.01) # sleep to make the "work" take longer
with output:
print(i)
# Collect the threads
threads = []
for i in range(10,100,10):
# Create 9 threads counting 10-19, 20-29, ... 90-99.
thread = threading.Thread(target=threadfunc,args=(i,i+10))
threads.append(thread)
# Start them all
for thread in threads:
thread.start()
# Wait for all to complete
for thread in threads:
thread.join()
答案 0 :(得分:0)
您还需要循环模式,但在单独的视图中,需要从id
$cmp
调用var
才能动态分配HTML id
模态和触发按钮:
@foreach($company as $cmp)
<tr>
<td>{{ $cmp->number }}</td>
<td>{{ $cmp->name}}</td>
<td> <a type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#modal{{$cmp->id}}" </td
</tr>
@include('path.modal')//Path of the view of a modal
@endforeach
在另一个视图中:
<!-- modal.blade.php -->
<div class="modal fade" id="modal{{$cmp->id}}"role="dialog">
<div class="modal-dialog">
<div class="modal-content">
...
</div>
</div>
</div>
答案 1 :(得分:0)
我假设您使用Bootstrap作为布局。
Documentation建议您绑定data-
属性以将值传递给模态。
您可以使用jQuery来处理show.bs.modal
事件。
您应该为按钮添加唯一标识符。例如data-modal-id
。像这样:
@foreach($company as $cmp)
<tr>
<td>{{ $cmp->number }}</td>
<td>{{ $cmp->name }}</td>
<td>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" data-modal-id="{{ $cmp->number }}">Button</button>
</td>
</tr>
@endforeach
在你的javascript中:
$('#myModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
var modal_id = button.data('modal-id');;
var modal = $(this);
// do whatever you want with your modal and modal_id
});