如何以嵌套形式使用 jQuery FIle Upload?
我正在尝试使用 https://github.com /blueimp/jQuery-File-Upload/wiki/Rails-setup-for-V5 在我的新 Rails 项目中。我想创建名为 assignments
的对象,并附加多个文件。
如何为作业制作一个表单,该表单具有用于上传文件的嵌套表单?
I'm trying to use https://github.com/blueimp/jQuery-File-Upload/wiki/Rails-setup-for-V5 in my new rails project. I want to make objects called assignments
that have multiple files attached to them.
How do I make a form for an assignment that has a nest form for the files being uploaded?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该插件更改输入[type=file]信息表单,当它位于其他表单内时,它是无效的。我解决了这个问题:将外部表单更改为
。我通过 jQuery 提交表单
当然,在提交表单之前,您必须在服务器端以某种方式管理上传。
This plugin change input[type=file] info form and when it's inside other form it's invalid. I solved this: the outer form I changed to
<div id="form">
. I submit form via jQuery withOf course you have to manage uploads somehow on server-side before submitting form.
我这样做的方法是在主表单之外添加一个单独的表单,仅用于上传文件:
然后我将文件上传插件的一部分挂接到两个表单,如下所示:
基本上,我使用 jQuery-File-Upload 的 API 从外部上传表单上传文件。
请注意,我在触发外部上传表单上的“添加”时包含
child_id
,以便我知道哪个孩子触发了文件上传。该值在每个回调的data
变量中可用。我抽象了很多,因为有很多应用程序特定的代码,希望你能从中弄清楚。
The way I did this is to add a separate form outside of my main form just for uploading files:
Then I hook part of the fileupload plugin to both forms, like so:
Basically, I use jQuery-File-Upload's API to upload the file from an external upload form.
Note that I include the
child_id
when triggering the 'add' on the external upload form so that I know which child has triggered a file upload. That value is available in thedata
variable in each callback.I have abstracted a lot as there's a lot of application specific code, hopefully you can figure it out from there.