【发布时间】:2020-11-27 14:30:09
【问题描述】:
我正在尝试使用 jquery 编辑数组值。这就是我所做的。
从模式中,每次我单击“添加项目”按钮时,它都会将值推送到数组中,然后将数据附加到表中
var iteminfo = {
"row": 'row' + cnt,
"make": make,
"body": body,
"cabin": cabin,
"horsepower": horsepower,
"wheels": wheels,
"chassis": chassis,
"engine": engine,
"remarks": remarks,
"shipmenttag": shipmenttag
};
trucksarray.push(iteminfo);
//append to table:
$("#truckstable > tbody").prepend(<tr><td>.....</td></tr>);
我的 html 表格如下所示:
现在我可以使用以下代码从数组中删除表格行和相应的数据:
//removing the table row
$("#truckstable").on('click', '.remrow', function () {
var id = $(".remrow").attr("id");
$(this).parent().parent().remove();
removeitem(id)
});
//removing array item
function removeitem(row) {
const itemToRemoveIndex = trucksarray.findIndex(function (item) {
return item.row === row;
});
if (itemToRemoveIndex !== -1) {
trucksarray.splice(itemToRemoveIndex, 1);
}
toastr.warning('Item removed!');
}
现在,我的问题是,如果我单击编辑按钮,应该会弹出一个模式并能够编辑选定的项目值、表格数据和数组值?有什么想法吗?
【问题讨论】:
-
你能让你的代码用 html 运行吗?
标签: html jquery html-table