Events Can';我不能让meteor文件收集包工作

Events Can';我不能让meteor文件收集包工作,events,meteor,packages,resumablejs,Events,Meteor,Packages,Resumablejs,不幸的是,我正在Windows计算机上工作,因此我必须手动将FileCollection包添加到我的应用程序中,但当我运行我的应用程序时,我可以从浏览器控制台访问文件收集和文件收集方法。然而,我似乎无法在实际页面上设置事件侦听器。(仅供参考,我正在使用iron router作为模板架构。) 似乎需要调用的代码没有按正确的顺序出现,但我已经尝试过将代码放置在何处,但似乎没有什么不同 服务器端代码: // Create a file collection, and enable file uploa

不幸的是,我正在Windows计算机上工作,因此我必须手动将FileCollection包添加到我的应用程序中,但当我运行我的应用程序时,我可以从浏览器控制台访问文件收集和文件收集方法。然而,我似乎无法在实际页面上设置事件侦听器。(仅供参考,我正在使用iron router作为模板架构。)

似乎需要调用的代码没有按正确的顺序出现,但我已经尝试过将代码放置在何处,但似乎没有什么不同

服务器端代码:

// Create a file collection, and enable file upload and download using HTTP
Images = new fileCollection('images',
  { resumable: true,   // Enable built-in resumable.js upload support
    http: [
      { method: 'get',
        path: '/:_id',  // this will be at route "/gridfs/images/:_id"
        lookup: function (params, query) {  // uses express style url params
          return { _id: params._id };       // a mongo query mapping url to myFiles
        }
      }
    ]
  }
);

if (Meteor.isServer) {

  // Only publish files owned by this userId, and ignore
  // file chunks being used by Resumable.js for current uploads
  Meteor.publish('myImages',
    function () {
      return Images.find({ 'metadata._Resumable': { $exists: false },
                   'metadata.owner': this.userId });
    }
  );

  // Allow rules for security. Should look familiar!
  // Without these, no file writes would be allowed
  Images.allow({
    remove: function (userId, file) {
      // Only owners can delete
      if (userId !== file.metadata.owner) {
        return false;
      } else {
        return true;
      }
    },
    // Client file document updates are all denied, implement Methods for that
    // This rule secures the HTTP REST interfaces' PUT/POST
    update: function (userId, file, fields) {
      // Only owners can upload file data
      if (userId !== file.metadata.owner) {
      return false;
      } else {
        return true;
      }
    },
    insert: function (userId, file) {
      // Assign the proper owner when a file is created
      file.metadata = file.metadata || {};
      file.metadata.owner = userId;
      return true;
    }
  });
}
客户端代码(当前位于client dir顶层的main.js中):


我认为问题可能在于使用IronRouter。我假设您正在通过Iron router使用一些layout.html,并且在其中添加了用于显示文件表的模板。(我猜您正在关注fileCollection附带的sampleApp。)。当我这样做的时候,我遇到了一个问题,这与我在哪里附加了监听器的代码有关。问题是您的客户端文件中的代码“Images.resubable.assignDrop($(“.fileDrop”);”在哪里。按照现在的方式,在layout.html中呈现模板之前,该行代码正在运行。因此代码找不到DOM元素“.fileDrop”。要修复此问题,请创建一个layout.js文件并使用以下呈现方法

Template.layout.rendered = function(){
    Images.resumable.assignDrop($(".fileDrop"));
} 

谢谢这就是我在让代码以正确的顺序执行方面所缺少的。不幸的是,我似乎把其他事情搞砸了,因为我只让它成功运行了一次。而且,我似乎无法复制我所做的。关于如何处理sampleApp中的其余代码有什么想法吗?在名为“collections”的顶级文件夹中保留一个文件可以吗?发现我的(最新)问题。这与文件收集无关。你的回答肯定能解决问题。
Template.layout.rendered = function(){
    Images.resumable.assignDrop($(".fileDrop"));
}