如何设计数据库架构来存储文章某些部分的注释?

时间:2018-08-20 07:09:34

标签: database-design

我打算设计一个博客系统,我想实现一个功能,让用户对文章的某些部分发表评论。该功能应如下所示。

enter image description here

问题在于,该文章可能会很长,用户可以选择其中的任何部分并发表评论。如何确定评论的文章部分?在这种情况下设计数据库架构的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

对于索引问题,我有一个非常简单的解决方案。当您使用JavaScript时,可以使用以下代码:

function logIndicesOfSelectedText() {
    //log the start index
    console.log(window.getSelection().anchorOffset);
    //log the end index    
    console.log(window.getSelection().focusOffset);
    //log the selected text
    console.log(window.getSelection().toString());
}

document.onmouseup = getIndicesOfSelectedText;

这只是将索引和选定的文本打印到控制台,但是使用它们应该是一件容易的事。