线程/嵌套评论

发布于 2024-09-24 05:42:03 字数 75 浏览 4 评论 0 原文

有人知道如何创建线程/嵌套评论系统吗?我想了解如何为我正在开发的博客执行此操作。我根本找不到任何有用的东西。肯定有人知道它是如何完成的。

Anyone know how to create a threaded / nested comment system? I would like to learn how to do this for my blog that I am working on. I simply can't find anything useful out there. Some one surely must know how its done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江南月 2024-10-01 05:42:03

很难相信,在 ASP.NET 出现 8 年之后,竟然没有人费心写一篇简单的文章或教程来介绍如何完成数百万博客中常用的线程注释之类的功能。搜索引擎像往常一样只产生垃圾。话又说回来,Google 是一个毫无价值的东西,你知道吗。

这就是为什么 asp.net 需要这么长时间来学习。并不是说这是脑部手术,只是事实上,超越书本上的基本内容是不可能的,因为信息不存在。

我花了一整天的时间思考这个问题,最后用一张表解决了这个问题。评论,两个分别处理评论和回复的存储过程,一个用于准确显示缩进评论所属位置的列表视图,另一个用于评论表单的列表视图。最重要的是,线程的深度没有限制,并且评论会被缓存。

在我的评论数据库表中,我创建了一个新列,用于存储在存储过程中计算的排序值。对于评论,排序值设置为等于其自己的评论 id 值,对于评论回复,该值设置为等于父排序 id 与其自己的评论 id(以点分隔)连接。如果排序 ID 没有点,则它是顶级评论。一个点等于一级深度,两个点等于二级深度,等等。

因此,我必须编写的唯一代码是两个简单的存储过程和一些 C# 来获取点的数量并为缩进分配适当的 css 值。我不需要多个带有外键的表、父子 ID 关系、复杂的代码或少数实际上在论坛上愿意回答的人通常建议的任何异国情调的建议。

快速、高效,工作起来很有魅力。常识规则!

It is hard to believe that after 8 years of asp.net, no one has bothered to write a simple article or tutorial on how something like threaded comments that are so commonly used on millions of blogs is done. Search engines yield nothing but garbage as usual. Then again, Google is a worthless piece of you know what.

This is why asp.net takes such a long time to learn. Not that it is brain surgery, only the fact that getting beyond the basic stuff present in books is impossible because the information does not exist.

I spent a whole day thinking about this and finally solved the problem using a single table for comments, two stored procedures handling comments and replies separately, a listview for displaying the indented comments exactly where they belong and another listview for the comment form. Best of all, there is no limit to the depth of threads and the comments are cached.

I my comments database table, I created a new column that stores the sorting value calculated in the stored procedures. For comments the sorting value is set equal to its own comment id value and for comment replies the value is set equal to the parent sorting id concatenated with it's own comment id separated by a dot. If a sorting id has no dots, it is a top level comment. One dot equals one level depth, two equals two level depth etc.

So, the only code I had to write was two simple stored procedures and a bit of C# to get the number of dots and assign the appropriate css value for indentation. I did not need multiple tables with foreign keys, parent-child id relationships, complicated code or any of the exotic recommendations commonly suggested by the few who actually bother to answer on forums.

Fast, efficient and works like a charm. Common sense rules!

酒几许 2024-10-01 05:42:03

如果您正在接受编辑器的建议,可以使用 WMD:Wysiwym Markdown 编辑器

WMD 是一个简单、轻量级的 HTML 编辑器,用于博客评论、论坛帖子和基本内容管理。 您可以使用一行代码将 WMD 添加到任何文本区域。添加多一行实时预览。 WMD 几乎适用于所有现代浏览器,并且现在完全免费使用。

至于数据模型,除其他考虑因素外,您还必须决定注释嵌套的深度。

public interface IComment
{
    public int ID;
    public string Body;
    public string OwnerID;
    public DateTime CreatedOn;
    ...        
}

If you're taking suggestions for the editor, how about using WMD: The Wysiwym Markdown Editor

WMD is a simple, lightweight HTML editor for blog comments, forum posts, and basic content management. You can add WMD to any textarea with one line of code. Add live preview with one line more. WMD works in nearly all modern browsers, and is now completely free to use.

As for the data model, you'll have to decide, amongst other considerations, how deep that comment nest would be.

public interface IComment
{
    public int ID;
    public string Body;
    public string OwnerID;
    public DateTime CreatedOn;
    ...        
}
乱世争霸 2024-10-01 05:42:03

考虑一下您必须在此处解决一些问题。垃圾邮件、注册、规模等。

如果您想利用一些预构建的解决方案,请考虑:

Consider there are some issues that you'd have to navigate here. Spam, registration, scale, etc.

If you wanted to leverage some pre-built solution, consider:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文