【问题标题】:Get all comments for handsontable table获取所有关于掌上桌的评论
【发布时间】:2016-06-17 02:39:53
【问题描述】:

我正在使用handsontable 从 Excel 中粘贴数据。我想向某些单元格添加更多信息,一个表示 CSS 类的字符串。我认为最好的方法是使用comments 插件。 在那里我看到了有关如何添加 cmets 的信息,但我没有看到如何读取 cmets。 当我尝试时:

hot1 = new Handsontable(container, {
    data: getData(),
    rowHeaders: true,
    colHeaders: true,
    contextMenu: true,
    comments: true,
    cell: [
      {row: 1, col: 1, comment: 'Some comment'},
      {row: 2, col: 2, comment: 'More comments'}
    ]
});      

hot1.getData();

我只看到表格数据,没有任何关于 cmets 的信息。从文档看来,我可以访问特定单元格以获取它的 cmets,但如果我可以在一个命令中获取所有 cmets,则没有参考(类似于我获取数据的方式)。

你有什么想法吗?

【问题讨论】:

    标签: javascript handsontable


    【解决方案1】:

    我们可以使用getCellMeta 方法获取所有的cmets。

    var comments = [];
    hot1.getCellMeta().cell.forEach(allComments);
    console.log(comments)
    
    function allComments(element){
      comments.push(element.comment);
    }
    

    这是一个有效的JSfiddle

    【讨论】:

    • 我可以收听任何事件以跟踪所有评论更改吗?如您所见here 我试图将您的函数添加到“afterChange”事件中,但是仅当我对其中一个单元格进行更改而不是在添加/删除评论时才调用此事件
    【解决方案2】:

    @Shlomi L 询问是否有一个事件可以绑定到当 cmets 更改时捕获。就在这里。它被称为:afterSetCellMeta。这是一个例子:

    afterSetCellMeta:  (row, col, source, val)  => {
           if(source == 'comment'){
                        console.log("[" + row + ", " + col + "]: " + source + " --> " + val);
                            console.log(source); //comment
                            console.log(val); //object containing value
                            this.saveUpdatedComment(val.value);
    
                        }
      }
    

    这将出现在 afterChange 之前或之后。这里是docs

    【讨论】:

      猜你喜欢
      • 2015-10-20
      • 1970-01-01
      • 1970-01-01
      • 2017-10-08
      • 2013-02-11
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 2011-04-18
      相关资源
      最近更新 更多