我有一个函数可以更新一行中每个单元格的注释。该函数被更高级别的函数多次调用,该函数循环遍历表中的每一行并确定要应用哪些注释。
这一切都运行良好。请参阅下面代码的简化版本。
// Loop through all hot rows and determine comment to apply
var loopThroughHotRows = function (hot) {
var rows = hot.getSourceData().length;
for (var i = 0; i < rows; i++) {
var comment = "some comment determined by another function";
applyResponseCommentsToRow(hot, comment, i);
}
}
// Apply comments to a whole row in a passed handsontable
var applyCommentsToRow = function (hot, comment, logicalrow) {
var cols = hot.countCols();
var commentsPlugin = hot.getPlugin('comments');
for (var i = 0; i < cols; i++) {
// render being issued for each comment set.
// need to restrict rendering somehow.
commentsPlugin.setCommentAtCell(logicalrow, i, comment);
}
}
问题在于每次将注释应用于单元格时。启动整个可手动实例的渲染。导致网络浏览器被阻止/突兀/变得非常缓慢且响应缓慢,直到所有渲染完成。
所以我的问题是。是否有某种方法可以阻止 Handsontable 在每次将新注释应用于单元格时进行渲染?要么暂时禁用所有渲染,要么以不同的方式添加注释?
最佳答案
我实际上最终自己找到了解决方案。如果通过调用hot.getCellMeta()函数设置单元格的注释。
这实际上绕过了handsontable的重新渲染。请参阅下面的更新功能。
// Apply comments to a whole row in a passed handsontable
var applyCommentsToRow = function (hot, comment, logicalrow) {
var cols = hot.countCols();
for (var i = 0; i < cols; i++) {
// New method of writing comment to cell. Does not cause handsontable re-render.
hot.getCellMeta(logicalrow, i).comment = {'value':responseComments};
}
// Call render once after all comments have been assigned to row!
hot.render();
}
关于javascript - 更新单元格注释时出现的可操作性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45430664/