像 stackoverflow 评论一样动态数据填充?

发布于 2024-10-20 12:35:41 字数 918 浏览 0 评论 0原文

我正在尝试创建一个像 SO 一样的评论系统,但首先,我想显示帖子的前 5 条评论,如果单击“显示所有评论”以获得所需的回复,则显示其余评论。

这样做的最佳方法是什么?我真的找不到一个好的方法来做我想做的事。我一定是错过了什么。

有关信息,评论数据源是我的页面中的嵌套转发器。外层转发器是回复,内层转发器是评论。目前我正在绑定所有结果的所有评论(即使它有 10000 个回复。)。另外,我不想对评论进行分页。我只是希望它能像SO一样工作。

有什么想法吗?

编辑:现在我正在考虑有 2 个表用于注释,它们是:

  • 一个只有 5 行数据且默认可见的表。我需要过滤才能做到这一点。 Linq 过滤代码会很棒!

  • 包含所有结果的表格。没有过滤。我对这个没有任何问题。

这是我的数据:

DataRowView dv = e.Item.DataItem as DataRowView;
        if (dv != null)
        {
            Repeater commentRepeater = e.Item.FindControl("childRepeater") as Repeater;
            if (commentRepeater != null)
            {
                commentRepeater.DataSource = dv.CreateChildView("myrelation");
                commentRepeater.DataBind();
            }
        }

如您所见,我已经在数据集中的表之间创建了关系,并将该数据行绑定到我的转发器。我需要对数据行进行前 5 名过滤。

谢谢

I'm trying to create a comment system just like SO has, but first, I'd like to show first 5 comments for a post and show rest if "display all comments" is clicked for the desired reply.

What is the best way of doing this? I really couldn't found a good way for doing what I want. I must be missing something.

For info, comments datasource is a nested repeater in my page. The outer repeater is replies and inner repeater is comments. Currently I'm binding all comments for all results (even if it has 10000 replies.). Also, I don't want to do paging for comments. I just want it to work the same way as SO.

Any ideas?

EDIT: Now I'm thinking of having 2 tables for comments which are:

  • A table which only has 5 rows of data and will be visible by default. I need filtering to do this. Linq filtering code would be great!

  • A table which has all the results. No filtering. I have no problems with this one.

So here is what I have for the data:

DataRowView dv = e.Item.DataItem as DataRowView;
        if (dv != null)
        {
            Repeater commentRepeater = e.Item.FindControl("childRepeater") as Repeater;
            if (commentRepeater != null)
            {
                commentRepeater.DataSource = dv.CreateChildView("myrelation");
                commentRepeater.DataBind();
            }
        }

As you can see, I have created a relation between tables in my dataset and I'm binding that datarow to my repeater. I need to do top 5 filtering on the datarow.

Thank you

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

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

发布评论

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

评论(2

贵在坚持 2024-10-27 12:35:41

如果您想将剩余的项目附加到当前的转发器项目,您可以在注释末尾有一个按钮,该按钮附加到 jquery 函数,该函数将为您获取其余的注释。然后,一旦收到数据,您的函数就会将注释附加到其他注释列表中,模仿中继器正在执行的操作并替换“显示全部”按钮。

如果您不想使用任何 ajax 来执行此操作,那么您可能需要使用一组新数据重新绑定注释 Repeater,该数据不仅限于前 5 个结果。

编辑:根据您的评论和您编辑的更改,我将使用一个包含所有评论的表格,并在每个评论的 DataBinding 中将行样式设置为可见,并使用全球计数器。一旦超过 5 个,请将每个项目的样式设置为隐藏样式。当他们单击“显示全部”按钮时,只需将隐藏的其余评论的样式从隐藏切换为可见即可。这将节省您重复前 5 项数据的时间,如果有很多带有注释的答案,这些数据可能会变成很多额外的行。

If you want to append the left over items to the current repeater item you could have a button at the end of the coments that is attached to a jquery function that will fetch the rest of the comments for you. Then once the data is recieved your function would just append the comments to the list of other comments mimicing what the repeater was doing and replacing the 'show all' button.

If you don't want to use any ajax to do this then you will probably need to rebind the comments Repeater with a new set of data that is not limited to just the first 5 results.

EDIT: Based on your comment and changes you have editted, I would go with one table with all comments and in the DataBinding of each comment set the row style to visible with a global counter. Once your have more than 5 set the style to a hidden style for each item. When they click the show all button, just switch the style from hidden to visible for the rest comments that are hidden. This will save you duplicating the data for the first 5 items which could turn into a lot of extra rows if there are a lot of answers with comments.

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