这是来自Post的Meteor编辑页面,我正在上传与Post关联的图像。
我需要访问当前的Post._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()无济于事。
答案 0 :(得分:0)
您应该在帖子的上下文中或找到该上下文。您可以使用Template.currentData
jQuery ajax success callback function definition(请记住,这是'模板',而不是您的'模板'var)如果您在帖子的上下文中,它应该有效。如果不是,您也可以尝试通过Template.parentData()
http://docs.meteor.com/#/full/template_currentdata找到它,这一切都取决于您的背景位置。