如何在流星中使用表单获取文件的内容?

时间:2017-08-17 20:34:10

标签: meteor

我正在尝试使用Meteor客户端中的表单获取JSON文件的内容,而不是控制台显示C:\fakepath\test.json的文件内容。

文件内容:

{"1420416000":{"DT":[{"type":"lg","pct":1,"price":2.9486,"ex":"p"}]}}

如果我将变量数据的值更改为event.target.collection.value,并使用collection html文本input的名称,则控制台将显示在表单中输入的文本字符串。

那为什么不使用该文件?

main.html中

<body>
        {{> upload}}
</body>

<template name="upload">
    <form>
      <input type="text" name="collection">      
      <input type="file" name="files" multiple> 
      <input type="submit" value="Upload">
    </form>
</template>

main.js

Template.upload.events({

  'submit form': function(event){
      event.preventDefault();
      data = event.target.files.value;
      console.log(data);
  }
});

谢谢,

0 个答案:

没有答案