【发布时间】:2015-05-08 14:07:41
【问题描述】:
我正在尝试创建一个简单的网络应用程序,它会要求用户填写一些问题,然后上传照片。当按下提交按钮时,我希望所有这些信息都存储在 Meteor 集合中,但是我在使用 FS Collection 包时遇到了一些困难。
这里是相关的main.html:
<form class="photoForm">
Problem: <input type = "text" id = "problem" placeholder="page # problem #"><br><br>
Your group members <input type = "text" id="group" size="50"> <br><br>
Your questions and comments about this problem: <br><br>
<textarea name="comments" form="photo" rows="4" cols="70" placeholder="Enter text here..."></textarea>
<br>
Upload a snapshot of your work here: <input type = "file" id = "myFileInput">
<br /><br />
<input type="submit" value="submit" />
</form>
这是 main.js:
Template.form.events({
'click input[type=submit]': function(event, template) {
console.log("form submit")
event.preventDefault();
FS.Utility.eachFile(event, function(file) {
Images.insert(file, function (err, fileObj){
//Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
});
});
}
});
这是我的问题:
我只能在“更改 .myFileInput”事件中获取要上传的文件。我试图让它在“点击输入[类型=提交]”和“提交”上上传,但它没有上传文件。单击提交按钮时,有没有办法让它上传文件?
如何将各种文本字段中的数据添加到图像集合中?我可以将这些添加合并到 Images.insert() 命令中吗?
【问题讨论】: