Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript FS.Collection实例在使用find()时返回未定义_Javascript_Meteor - Fatal编程技术网

Javascript FS.Collection实例在使用find()时返回未定义

Javascript FS.Collection实例在使用find()时返回未定义,javascript,meteor,Javascript,Meteor,我在网络开发方面有点新手,所以如果我错误地使用了FSCollection,我深表歉意 我有一个FS.Collection实例,它接收音频文件 LectureAudio = new FS.Collection("lectureAudio", { stores: [new FS.Store.FileSystem("lectureAudio", { path:"~/digicog/audioUpload", filter: { allow

我在网络开发方面有点新手,所以如果我错误地使用了FSCollection,我深表歉意

我有一个FS.Collection实例,它接收音频文件

LectureAudio = new FS.Collection("lectureAudio", {
    stores: [new FS.Store.FileSystem("lectureAudio", {
        path:"~/digicog/audioUpload",
        filter: {
            allow: {
                contentTypes: ['audio/*'],
                extensions: ['mp3', 'wav', 'MP3', 'WAV']
            }
        }
    })]
});
我使用输入文件元素将音频文件插入到集合中

Template.audioControl.events({
  'change #lecAudioPath': function (event) {
    var files = document.getElementById("lecAudioPath").files;
    if(files.length != 0){  
      var lecName = Router.current().params._id;
      var audioFile = new FS.File(files[0]);
      audioFile.metadata = {LectureId: lecName};
      LectureAudio.insert(audioFile);
    }
   }
});
但是,当我在控制台中键入
teacheAudio.find().fetch()
进行测试时,会得到空括号[]。 即使我使用以下方法检查我的mongo数据库:

>db.getCollection("cfs.lectureAudio.filerecord").find()
我看到我的收藏被填充了

{ "_id" : "wwyQtZZNwicbheCch", "copies" : { "lectureAudio" : { "name" : "fWnQyQpEWSXRDeuJq.mp3" } }, "original" : { "name" : "test1.mp3", "updatedAt" : ISODate("2013-08-16T16:07:40Z"), "size" : 8087475, "type" : "audio/mp3" }, "uploadedAt" : ISODate("2015-03-07T06:05:53.589Z") }
{ "_id" : "3rBbFfnGAT3Z8Bkti", "copies" : { "lectureAudio" : { "name" : "Efn235HcCyGrm5TPx.mp3" } }, "original" : { "name" : "test2.mp3", "updatedAt" : ISODate("2013-08-16T16:07:52Z"), "size" : 8806339, "type" : "audio/mp3" }, "uploadedAt" : ISODate("2015-03-07T06:17:06.234Z") }
{ "_id" : "RJ7LLH7XhgG2PnP9g", "copies" : { "lectureAudio" : { "name" : "fWnQyQpEWSXRDeuJq.mp3" } }, "original" : { "name" : "test3.mp3", "updatedAt" : ISODate("2013-08-16T16:07:52Z"), "size" : 8806339, "type" : "audio/mp3" }, "uploadedAt" : ISODate("2015-03-07T06:18:30.454Z") }
{ "_id" : "9YY33kFFbP7oBMjmr", "copies" : { "lectureAudio" : { "name" : "y7KQmq3ReqcP7Pzyw.mp3" } }, "original" : { "name" : "test4.mp3", "updatedAt" : ISODate("2013-08-16T16:07:40Z"), "size" : 8087475, "type" : "audio/mp3" }, "uploadedAt" : ISODate("2015-03-07T20:50:21.226Z") }

如何显示收藏?

您可能忘记了发布和订阅收藏

Template.audioControl.events({
  'change #lecAudioPath': function (event) {
    var files = document.getElementById("lecAudioPath").files;
    if(files.length != 0){  
      var lecName = Router.current().params._id;
      var audioFile = new FS.File(files[0]);
      audioFile.metadata = {LectureId: lecName};
      LectureAudio.insert(audioFile);
    }
   }
});
在服务器上:

Meteor.publish('lecture_audio', function () {
  return LectureAudio.find();
}
和客户:

Meteor.subscribe('lecture_audio');

文档中的更多信息

是!真管用,谢谢你!我在服务器文件夹和路由器中发布了模板在waitOn语句中呈现的页面,但由于某些原因,这些页面不起作用。