1

我有个问题。它是关于编辑表格中的选定行。表格中的每一行在末尾都有用于编辑自我的按钮。如果单击此按钮,我可以看到编辑窗口以编辑表中选定的数据行。我正在使用 Bootstrap,但遇到了问题。如何获取编辑窗口并在编辑窗口上单击保存以用新值替换所选行?
最好看我的例子!

这是我的 **演示

添加新行的按钮

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  + Define a new visual feature
</button>

表添加新行。

    <table class="table table-striped" id="table-visual-features">
        <thead>
            <tr>
                <th>Visual Feature</th>
                <th>Type [currently not used]</th>
                <th>Description</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>

这是一个值,在表中的选定行中具有该值。我想使用 Bootstrap 使用编辑窗口编辑此值

    console.log($(this).closest('tr').children('td').eq(0).text());
    console.log($(this).closest('tr').children('td').eq(1).text());
    console.log($(this).closest('tr').children('td').eq(2).text())
4

1 回答 1

0

您需要对要编辑的行的引用。例如,您可以做的是这样的事情:

var $table = $('#table-visual-features');
$table.on('click', 'tbody tr button[data-target=#edit]', function (event) {
    var $rows = $table.find('tbody tr');
    var $thisRow = $(this).parents('tr').eq(0);
    var index = $rows.index($thisRow);
    // open your modal here; now you know which row to edit
});
于 2013-11-12T19:47:50.130 回答