Bootstrap模态传递数据通过on('click-row.bs.table'

Bootstrap Modal passing data through on('click-row.bs.table'

我必须 Bootstrap 模态 Windows... 一个带有 table(#items),另一个 (#item) 带有表单数据。

现在我想单击 table 中的一行并打开另一个模式 windows 并希望通过它传递数据。

$('#items-table').on('click-row.bs.table', function (e, row, $element) {
    $('#items').modal('hide');
    $('#item').modal('show');
    //Need to pass row.id to #item
});

这是我从 table 行捕获点击的地方。在这里,我得到了我想在我的 #item 表单中使用的 row.id

$('#item').on('shown.bs.modal', function (event) {
  var button = $(event.relatedTarget); // Button that triggered the modal
  var itemId = button.data('item-id') ;// Extract info from data-* attributes

})

站在那里的这两行来自一个具有数据属性的按钮。这工作正常,但我如何从 table?

传递 row.id

所以我想办法妥善处理:

    $('#items-table').on('click-row.bs.table', function (e, row, $element) {
    $('#items').modal('hide');
    $modal('#item');
    $modal.data('id', row.id);
    $modal.modal('show');
    //Need to pass row.id to #item
});

并在模式中捕捉它,例如:

$('#item').on('shown.bs.modal', function (event) {

  var modal = $(this);
  var id = modal.data('id');

})

非常感谢@wenyi link!