簡體   English   中英

Meteor.js-將不顯示訂閱數據,僅顯示光標對象

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

為什么它沒有在模板中顯示文件記錄? 它返回模板的唯一內容就是“光標”對象。

JS控制台中的console.log(file)輸出是什么:

 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;
  }
});

'/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>

請記住,這是世界上最愚蠢的錯誤:流星中的模板名稱必須為大寫!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM