Why isn't it displaying a file record in my template? The only thing it returns to the template is just the 'cursor' object.
为什么不在我的模板中显示文件记录?它返回模板的唯一方法就是'光标'对象。
What the console.log(file) output is in the JS console:
console.log(文件)输出在JS控制台中的内容:
FilesCollection {collectionName: "Files", downloadRoute: "/cdn/storage", schema: Object, chunkSize: 524288, namingFunction: false…}
I've looked at every post, etc. I realize it returns a cursor to the client, but I'm doing a Files.findOne() query, which should return the record itself to the template / html.
我查看了每个帖子等等。我意识到它会将光标返回给客户端,但我正在做一个Files.findOne()查询,它应该将记录本身返回给模板/ html。
'/imports/api/files.js'
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
export const Files = new FilesCollection({
collectionName: 'Files',
allowClientCode: false, // Disallow remove files from Client
onBeforeUpload: function (file) {
// Allow upload files under 10MB, and only in png/jpg/jpeg formats
if (file.size <= 10485760 && /png|jpg|jpeg/i.test(file.extension)) {
return true;
} else {
return 'Please upload image, with size equal or less than 10MB';
}
}
});
if (Meteor.isServer) {
// This code only runs on the server
Meteor.publish('getFile', function(id) {
return Files.find({_id: id }).cursor;
});
}
'/imports/ui/components/download.js'
import './download.html';
import { Files } from '../../api/files.js';
Template.download.onCreated(function() {
let self = this;
self.autorun(function() {
let fileId = FlowRouter.getParam('id');
self.subscribe('getFile', fileId);
});
});
Template.download.helpers({
file: function () {
let fileId = FlowRouter.getParam('id');
let file = Files.findOne({_id: fileId}) || {};
console.log(file)
return file;
}
});
'/imports/ui/components/download.html'
<template name='download'>
{{#if Template.subscriptionsReady}}
{{#with file}}
<a href="{{link}}?download=true" download="{{name}}" target="_parent">
{{name}}
</a>
<p>{{link}}</p>
<h1>subscriptions are ready!</h1>
<h2>{{collectionName}}</h2>
{{/with}}
{{else}}
<p>Loading...</p>
{{/if}}
</template>
1 个解决方案
#1
0
World's dumbest mistake, remember: template names in Meteor must be in Upper case!
世界上最愚蠢的错误,记住:Meteor中的模板名称必须是大写的!
#1
0
World's dumbest mistake, remember: template names in Meteor must be in Upper case!
世界上最愚蠢的错误,记住:Meteor中的模板名称必须是大写的!