gpt4 book ai didi

datatables - jQuery DataTables - 使用 jQuery 对象替换/更新行。或者 fnUpdate

转载 作者:行者123 更新时间:2023-12-03 18:47:15 29 4
gpt4 key购买 nike

我使用以下代码成功地向数据表中添加了一行:

作品:

var serversTable = $('#datatable-table').dataTable().api();

var serverRowTemplate = Handlebars.compile($('#serverRowTemplate').html());

var $row = $(serverRowTemplate(data.results[r]));

serversTable.row.add($row).draw(false);

但是当我尝试使用类似的方法更新(替换)一行时,我没有运气。我也试过使用 fnUpdate,但我似乎无法找出通过 jQuery 对象基本上替换/更新现有行的正确方法。这是无法更新表格的代码:

不起作用:

var serversTable = $('#datatable-table').dataTable().api();

var oldRow = $('#dashboardTemplateContainer tr[data-tag="'+ data.results[r].tag + '"]'); // select the row i'm looking for

var serverRowTemplate = Handlebars.compile($('#serverRowTemplate').html()); //compiles the handlebars template. i need this template as i have a lot of conditionals etc.

var $row = $(serverRowTemplate(data.results[r])); // turning the template into a jQuery object worked for the row.add() function in the above example.

serversTable.rows(oldRow).data($row).draw(false); // replace the old row with the new row. doesn't work.

有什么建议吗?

最佳答案

API 方法 rows().data() 只能用于检索数据。使用 row().data() 而是为一行设置数据。

但是,您将无法为 <TR> 使用 jQuery 对象节点更新行的数据。在这种情况下,最好的选择可能是删除带有 row().remove() 的行。如果你只有 <TR>,则重新添加它节点。

关于datatables - jQuery DataTables - 使用 jQuery 对象替换/更新行。或者 fnUpdate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31776781/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com