线程/嵌套评论
有人知道如何创建线程/嵌套评论系统吗?我想了解如何为我正在开发的博客执行此操作。我根本找不到任何有用的东西。肯定有人知道它是如何完成的。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
有人知道如何创建线程/嵌套评论系统吗?我想了解如何为我正在开发的博客执行此操作。我根本找不到任何有用的东西。肯定有人知道它是如何完成的。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
很难相信,在 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!
如果您正在接受编辑器的建议,可以使用 WMD:Wysiwym Markdown 编辑器
至于数据模型,除其他考虑因素外,您还必须决定注释嵌套的深度。
If you're taking suggestions for the editor, how about using WMD: The Wysiwym Markdown Editor
As for the data model, you'll have to decide, amongst other considerations, how deep that comment nest would be.
考虑一下您必须在此处解决一些问题。垃圾邮件、注册、规模等。
如果您想利用一些预构建的解决方案,请考虑:
Ment-O-Matic - 允许 ASP.NET 平台的用户轻松地将评论功能添加到现有博客或类似的基于 Web 的软件中。警告! .NET 1.1
从任何 CodePlex 的博客项目。
使用Subkismet进行反垃圾评论过滤。
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:
Ment-O-Matic - allows users of ASP.NET platform to easily add commenting facility to an existing blog or similar web-based software. Warning! .NET 1.1
borrow inspiration from any blog projects at CodePlex.
use Subkismet for anti-spam comment filtering.