js -不显示订阅数据,只显示游标对象
Meteor.js - Won't display subscription data, only the cursor object
为什么在我的模板中不显示文件记录?它唯一返回给模板的就是'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中的模板名必须大写!
相关文章:
- 从桌面读取python文件时高亮显示代码
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何在生成下载文件时显示加载动画
- React重新渲染但未显示正确的组件
- nodejs-expressjs上传图像并显示它们
- 使用JSP从服务器检索和显示图像
- 音频控件在mouseover上显示,在mouseout上淡出
- 让文本输入幻灯片显示输入时的新文本输入?然后向后滑动
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 显示5秒后隐藏潜水
- 画廊图像未显示
- 不显示带有本地json文件数据的谷歌地图脚本
- 如何将json数据显示为html
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 高亮显示时编辑文本大小和颜色
- CKEditor显示多个游标
- 在处理查询时显示繁忙的游标
- js -不显示订阅数据,只显示游标对象
- 返回的游标数组不会显示任何结果