Просто хочу получить данные строки таблицы и передать ее. В моем коде кажется, что он только получает данные первой строки.
$(".edit").click(function(){
var tableData = $('tr.table').children("td").map(function() {
return $(this).text();
}).get();
$('#test1').val($.trim(tableData[0]));
$('#test2').val($.trim(tableData[1]));
$('#test3').val($.trim(tableData[2]));
})
Пытаться
var tableData = $(this).closest('tr.table').children("td").map(function () {
return $(this).text();
}).get();
$('tr.table').children("td")
//will get all tr.table and it children td
в
$(this).closest('tr.table').children("td")
//this will get closest tr to the current edit button
$(".edit").click(function(){
var tableData = $(this).closest("tr").children("td").map(function() {
// by $(this) go to current td then by closest go its closest "tr" then find their td
return $(this).text();
}).get();
$('#test1').val($.trim(tableData[0]));
$('#test2').val($.trim(tableData[1]));
$('#test3').val($.trim(tableData[2]));
});
ссылка ближайшая()
.edit
находится элемент.edit
?$('tr.table').children("td")
получает все элементыtd
всей таблицы.