js -不显示订阅数据,只显示游标对象

Meteor.js - Won't display subscription data, only the cursor object

本文关键字:显示 游标 对象 数据 js      更新时间:2023-09-26

为什么在我的模板中不显示文件记录?它唯一返回给模板的就是'cursor'对象。

JS控制台中console.log(文件)的输出:

 FilesCollection {collectionName: "Files", downloadRoute: "/cdn/storage", schema: Object, chunkSize: 524288, namingFunction: false…}

我已经看了每一个帖子,等等。我意识到它返回一个游标到客户端,但我正在做一个Files.findOne()查询,它应该将记录本身返回到模板/html。

/进口/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;
});
}

/进口/ui/组件/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/组件/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>

世界上最愚蠢的错误,记住:Meteor中的模板名必须大写!