1

考虑到这个要求。

在您发布新帖子之前,在编辑时,有一个预览面板会在您输入时呈现您的帖子内容。

因为它不是一个真正的帖子,我们只希望它只会更新(并从中检索内容)本地 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()

以上所有都没有效果。

对不起我糟糕的英语。

4

2 回答 2

6

它会在你的助手中。

您像往常一样插入文档。但是在查看它时,您可以打开和关闭反应性。

Template.newPost.helpers({
    yourpost:function() {
        return YourPosts.find({},{reactive: false});
    }
});

您在or查询reactive: false中作为选项传递。您可以使用 a 之类的东西来获取其真值或假值,然后在需要时更改它。findfindOneSession

于 2013-10-29T11:13:42.557 回答
0

您始终可以使用辅助(仅限客户端)集合:

var cache = new Meteor.Collection(null); // no-name

您可以在编辑文档的同时播放文档,并最终在用户按下save按钮时将所有更改复制到原始集合。

于 2013-10-31T00:11:25.820 回答