0
爲什麼它不顯示我的模板中的文件記錄?它返回到模板的唯一東西就是'遊標'對象。Meteor.js - 不會顯示訂閱數據,只顯示光標對象
中的console.log(文件)輸出爲JS控制檯什麼:
FilesCollection {collectionName: "Files", downloadRoute: "/cdn/storage", schema: Object, chunkSize: 524288, namingFunction: false…}
我看每一個崗位,等我意識到它返回一個指針到客戶端,但我做一個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;
}
});
「/進口/ UI /組件/下載。 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>