2016-03-03 45 views
0

我使用handsontable來粘貼來自excel的數據。我想向一些單元添加更多信息,一個表示CSS類的字符串。我認爲最好的方法是使用comments插件。 我在那裏看到有關如何添加評論的信息,但我看不到如何閱讀評論。 當我嘗試:獲取關於可分表的所有評論

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(); 

我只看到表中的數據沒有關於意見的任何信息。從文檔看來,我可以訪問特定單元格以獲得它的評論,但是如果我可以在一個命令中獲得所有評論(與我如何獲取數據相似),則沒有參考文獻。

你有什麼想法嗎?

回答

0

我們可以使用getCellMeta方法得到所有評論。

var comments = []; 
hot1.getCellMeta().cell.forEach(allComments); 
console.log(comments) 

function allComments(element){ 
    comments.push(element.comment); 
} 

這是一個工作JSfiddle

+0

是否有任何事件可以用來跟蹤所有評論更改?正如你可以看到[這裏](http://jsfiddle.net/4hzmeabf/28/)我試圖添加你的函數到「afterChange」事件,但是這個事件只是在我改變其中一個單元格,而不是當我添加/刪除評論時 –

0

@Shlomi L詢問是否有一個事件可以綁定到評論改變時捕捉。就在這裏。它被稱爲: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