考虑到这个要求.
在发布新帖子之前,在编辑时,会有一个预览面板,可在您键入时呈现您的帖子内容.
因为它不是真正的帖子,我们只希望它只会更新(并从中检索内容)本地mongodb并且不希望这个帖子会同步到服务器.如何实现?
我在模板中试过这个
Template.newPost.events
'keyup .post-content' : (event, templ)->
event.preventDefault()
Deps.nonreactive ->
Post.update({_id: post_id}, {content: event.currentTarget.value })
Run Code Online (Sandbox Code Playgroud)
还有这个
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()
Run Code Online (Sandbox Code Playgroud)
以上所有都没有效果.
抱歉我的英语不好.
这将是你的助手.
您可以像平常一样插入文档.但在查看时,您可以打开和关闭反应.
Template.newPost.helpers({
yourpost:function() {
return YourPosts.find({},{reactive: false});
}
});
Run Code Online (Sandbox Code Playgroud)
您reactive: false在您find或findOne查询中作为选项传递.您可以使用类似a的东西Session来获取其真值或假值,然后在需要时更改它.
| 归档时间: |
|
| 查看次数: |
2324 次 |
| 最近记录: |