考虑这个要求。
在发布新帖子之前,在编辑时,会有一个预览面板,可在您输入时呈现您的帖子内容。
因为它不是真正的帖子,我们只是希望它只会更新(并从中检索内容)本地mongodb,并且不希望此帖子将同步到服务器。 如何实现?
我在模板中试过这个
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()
以上所有都没有效果。
抱歉我的英语很差。
答案 0 :(得分:6)
这将是你的助手。
您可以像平常一样插入文档。但在查看时,您可以打开和关闭反应。
Template.newPost.helpers({
yourpost:function() {
return YourPosts.find({},{reactive: false});
}
});
您在reactive: false
或find
查询中作为选项传递findOne
。您可以使用类似Session
的内容来获取其真值或假值,然后在需要时更改它。
答案 1 :(得分:0)
您始终可以使用辅助(仅限客户端)集合:
var cache = new Meteor.Collection(null); // no-name
您可以在编辑文档时播放文档,并在用户按下save
按钮时将所有更改复制到原始文档。