如何临时禁用反应性并仅更新/检索本地mongodb? [英] How to disable reactivity temporarily and just update/retrieve local mongodb?
问题描述
考虑此要求.
在发布新帖子时,在编辑的同时,会有一个预览面板,该面板将在您键入内容时呈现您的帖子内容.
Before you publishing a new post, while editing, there is a preview panel which will render your post contents as you typing.
因为它不是真实的帖子,所以我们只希望它仅更新本地mongodb(并从中检索内容),并且不希望此帖子将被同步到服务器. 如何实现呢?
Because it is not a real post, we just want it will only update ( and retrieve content from) local mongodb and do not want this post will be synced to server. How to implement that?
我在模板中尝试过
Template.newPost.events
'keyup .post-content' : (event, templ)->
event.preventDefault()
Deps.nonreactive ->
Post.update({_id: post_id}, {content: event.currentTarget.value })
还有这个
Template.newPost.events
'keyup .post-content' : (event, templ)->
event.preventDefault()
Meteor.call 'updatePostContent', post_id, event.currentTarget.value
Meteor.methods
updatePostContent: (postId, value)->
if (this.isSimulation)
Post.update({_id: postId}, {content: value })
else
this.stop()
以上所有内容均无效.
对不起,我的英语不好.
Sorry for my poor english.
推荐答案
它将在您的助手中.
您可以像平常一样插入文档.但是在查看时,您可以打开和关闭反应性.
You insert the document like normal. But when viewing it you can switch reactivity on and off.
Template.newPost.helpers({
yourpost:function() {
return YourPosts.find({},{reactive: false});
}
});
您可以在find
或findOne
查询中忽略reactive: false
作为选项.您可以使用Session
之类的东西来获取其真值或假值,然后在需要时进行更改.
You pass off reactive: false
as an option in your find
or findOne
query. You could use something like a Session
to get its true or false value then change it when you need to.
这篇关于如何临时禁用反应性并仅更新/检索本地mongodb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!