Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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
Jquery Dropzone是否将行数添加到表中,并将文件数添加到Dropzone?_Jquery_Dropzone.js - Fatal编程技术网

Jquery Dropzone是否将行数添加到表中,并将文件数添加到Dropzone?

Jquery Dropzone是否将行数添加到表中,并将文件数添加到Dropzone?,jquery,dropzone.js,Jquery,Dropzone.js,我正在使用jQuery。在dropzone下,我有一个带有如下标记的表 <table id="data"> <tr> <td>Name</td> <td>Email</td> <td>Phone</td> </tr> </table> Dropzone.options.documentDropzone = {

我正在使用jQuery。在dropzone下,我有一个带有如下标记的表

<table id="data">
    <tr>
        <td>Name</td>
        <td>Email</td>
        <td>Phone</td>
    </tr>
</table>
Dropzone.options.documentDropzone = {
    init: function () {
        this.on("complete", function (file) {
            if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
                var Length = this.getAcceptedFiles().length; // To get the number of files in the dropzone
                // Loop to add number of rows after adding files to dropzone
                for(i=0; i < Length; i+) {
                            var html = $('<tr><td><input type=\"text\" name=\"name\"></td><td><input type=\"text\" name=\"email\"></td><td><input type=\"text\" name=\"phone\"></td></tr>');
                            $('table#data').append(html);
                        }
            }
        }
    }
}

名称
电子邮件
电话
假设我在dropzone中删除了3个文件,因此我希望表中显示3行输入字段。因此,我将我的js制作成这样

<table id="data">
    <tr>
        <td>Name</td>
        <td>Email</td>
        <td>Phone</td>
    </tr>
</table>
Dropzone.options.documentDropzone = {
    init: function () {
        this.on("complete", function (file) {
            if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
                var Length = this.getAcceptedFiles().length; // To get the number of files in the dropzone
                // Loop to add number of rows after adding files to dropzone
                for(i=0; i < Length; i+) {
                            var html = $('<tr><td><input type=\"text\" name=\"name\"></td><td><input type=\"text\" name=\"email\"></td><td><input type=\"text\" name=\"phone\"></td></tr>');
                            $('table#data').append(html);
                        }
            }
        }
    }
}
Dropzone.options.documentDropzone={
init:函数(){
此.on(“完成”,函数(文件){
if(this.getUploadingFiles().length==0&&this.getQueuedFiles().length==0){
var Length=this.getAcceptedFiles().Length;//获取dropzone中的文件数
//循环以在向dropzone添加文件后添加行数
对于(i=0;i

在这里,它工作得很好,比如说我第一次添加了3个文件,所以它很好地添加了3行。另一次,我添加了2个文件。所以在dropzone中,我现在有3+2=5个文件。所以它应该显示5个文件行。但是它是这样显示的,首先显示了3个文件,然后当我添加另外2个文件时,它显示为3+(3+2)=8.有人能告诉我如何解决这个问题吗?任何帮助和建议都会非常有用。谢谢

使用
removeAllFiles
方法将计数器重置回0;假设您使用的是表格来显示上传的文件,而不是dropzone本身

this.on('complete', function() {
    if (! this.getUploadingFiles().length && ! this.getQueuedFiles().length) {
        var Length = this.getAcceptedFiles().length;
        for (var i = 0; i < Length; i++) {
            var html = $('<tr><td><input type=\"text\" name=\"name\"></td><td><input type=\"text\" name=\"email\"></td><td><input type=\"text\" name=\"phone\"></td></tr>');
            $('table#data').append(html);
        }
        this.removeAllFiles();
    }
});
this.on('complete',function(){
如果(!this.getUploadingFiles().length&!this.getQueuedFiles().length){
var Length=this.getAcceptedFiles().Length;
对于(变量i=0;i

编辑:似乎误解了问题,抱歉。添加新文件时,您可以重新绘制表格,如执行
$('table#data').html(html)
-但这有一个缺点,即清除表单中已经存在的内容,丢失任何活动/焦点状态等。根据我对Dropzone的体验,您必须调用
removeAllFiles
,以停止跟踪较旧的上载。因此,如果您可以使用Dropzone作为上载文件的手段,而不将其用于显示,那么我会同意我上面的建议。

根本不起作用。this.removeAllFiles();正在删除我认为的所有文件。你能重新检查吗?是的,我再次阅读了你的问题,我认为我的想法是错误的。我自己也遇到过这个问题,但决定只使用Dropzone作为上传程序,而不是用于在以后显示上传的文件。我不完全确定是否可以将上传的文件保留在dro中pzone并将其计数重置为零。