不要对 Meteor 中的更新进行反应排序 [英] Do not reactive sort on update in Meteor

查看:45
本文介绍了不要对 Meteor 中的更新进行反应排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个直观显示的帖子列表.每个帖子都按其投票排序.

I have a list of posts visually displayed. Each post is sorted by its votes.

Posts.find({}, {sort: {votes: -1, name: 1}})

现在当用户点击帖子上的 upvote 时,我会做一个

Now when a user clicks upvote on a post, I do a

Posts.update(id, {$inc: {votes: 1}});

现在由于它是按投票排序的,项目在列表中向上/向下移动,用户失去了上下文.他必须搜索它移动到的项目.

Now since it is sorted by votes, the item moves up/down in the list and the user looses the context. He has to search for the item where it has moved to.

如何告诉meteor 在更新时不要移动项目?

How do I tell meteor to not move the item on update?

我检查了 Collections.update 函数,它不支持 reactive: false

I checked the Collections.update function, it doesn't support reactive: false

推荐答案

您必须在 find 方法中使用 reactive:false(它将数据传递给把手).

You have to use the reactive:false in the find method (it passes on the data to handlebars).

Posts.find({}, {sort: {votes: -1, name: 1}, reactive: false}});

这样它就不会监听更新(插入/更新/移动/删除)

So that it doesn't listen for updates (insert/update/move/delete)

如果您需要对其进行自定义以使其仅用于更新操作:

If you need to customize it so that its only for the update operation:

对于初学者,您需要删除 autopublish 包.

For starters you would need to remove the autopublish package.

您还需要手动订阅您的收藏集并从服务器发布它们.party 示例 展示了如何很好地做到这一点.

You also need to then subscribe to your collections manually and publish them from the server. The parties example shows how to do this quite well.

然后您需要编写自定义发布函数并更改 changed: 函数,以便在投票发生变化时不会向客户端发送任何数据.请注意,用户在刷新页面之前不会看到更新的投票数

Then you would need to write a custom publish function and alter the changed: function so that it doesn't send any data down to the client when votes changes. Note though that the user will not see the updated number of votes until they refresh the page

这篇关于不要对 Meteor 中的更新进行反应排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆