Meteor 获取当前文档/模板_流星事件中使用的id

Meteor 获取当前文档/模板_流星事件中使用的id,meteor,Meteor,这是一篇文章的Meteor编辑页面,我正在上传与文章相关的图片 我需要访问当前帖子。\u id才能添加到其图像对象。如何从模板事件中获取它 Template.eventEdit.events({ ... 'change .header-file-path': function(e, template) { FS.Utility.eachFile(e, function(file) { Images.insert(file, function (err, f

这是一篇文章的Meteor编辑页面,我正在上传与文章相关的图片

我需要访问当前帖子。\u id才能添加到其图像对象。如何从模板事件中获取它

Template.eventEdit.events({

  ...

  'change .header-file-path': function(e, template) {    
    FS.Utility.eachFile(e, function(file) {
      Images.insert(file, function (err, fileObj) {
        Posts.update({_id: CURRENTPOST._id}, {$push: {images: fileObj._id}});
      });
    });
  }

});

我尝试了template.data和template.currentData(),但没有效果。

您应该在文章的上下文中找到上下文。您可以使用
Template.currentData
(请记住,这是“模板”而不是您的“模板”变量),如果您在文章的上下文中,它应该可以工作。如果没有,您也可以尝试通过
Template.parentData()
找到它,这取决于您的上下文位置。

谢谢您的回复,非常感谢-我一定错过了一些重要的东西-都是console.log(Template.currentData());和console.log(Template.parentData());返回null。为了澄清这一点,我试图从活动中获取Ironrouter的id。我的路由器看起来像“router.route('/event/:_id/edit',{..})”,实际上-你是对的,我还有其他事情在进行-在我的例子中,Template.currentData()。_id和Template.parentData()都可以正常工作。。谢谢