[英]How to pass clicked/selected row data from one table to another table that are placed side by side
我有兩個並排放置的表,我會將第一個表上的選定行附加到第二個選項卡上
我設法從選定的行中獲取數據並將其轉換為數組。 我嘗試使用v-bind標記綁定第二個表中的數據值,但它不起作用
我希望單擊一個表中的一行,並將該行添加到另一個表中,該表僅位於另一個表的側面
我從您的問題中了解到的是,您正在尋找一種jquery代碼,每當用戶單擊任何表中的一行時,該代碼都會使兩個表中的行從一個表移動到另一個表。 例如,如果您單擊第一張表中的一行,它將移至第二張表;如果您單擊第二張表中的一行,它將移至第一張表。 如果是這樣,那么jQuery代碼可能是:
// identify the two tables with IDs for easier access
var tbl1=$('#table_1_id'), tbl2=$('#table_2_id');
// use tbody selector to make sure that you don't bind this event to table heading rows
$('#table_1_id,#table_2_id').find('tbody tr').on('click', moveRow);
function moveRow() {
// find on which table this row is
var row = $(this);
var table_current = row.closest('table');
// If current table ID equals to first table ID then it means we are in first table
if (table_current.prop('id')==tbl1.prop('id')) {
// Then we move the row to second table
tbl2.find('tbody').append(row);
} else {
// The row was in second table so we move it to first table
tbl1.find('tbody').append(row);
}
return;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.