最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get table row ID after dropzone event - Stack Overflow

programmeradmin1浏览0评论

I've been banging my head on this for hours so hopefully someone can help. I'm trying to fetch either the row id or the form id when a file is uploaded into a dropzone box. I have multiple table rows with multiple dropzone boxes.

Here is an example row from my table:

<table class="docs" id="show">      
    <tr class="doc" id="*Need_This*">
        <td>
            <div class="file_upload drop">
                <form class="dropzone clickable" id="*Or_Need_This*">
                </form>
            </div>
        </td>
    </tr>
</table>

Here is my jquery:

<script type="text/javascript">
$(document).ready(function(){
     $(".dropzone").dropzone({ 
        paramName: 'photos',
        url: "post.php",
        dictDefaultMessage: "Drag or Click",
        clickable: true,
        enqueueForUpload: true,
        init: function() {
            var id = $(this).closest('tr').attr('id');
            this.on("success", function(file) { alert(id); });
          }
    });
});
</script>

Right now it's returning undefined. I need to get the id's so that I can append css changes to other elements on the row. Any help is greatly appreciated!

I've been banging my head on this for hours so hopefully someone can help. I'm trying to fetch either the row id or the form id when a file is uploaded into a dropzone box. I have multiple table rows with multiple dropzone boxes.

Here is an example row from my table:

<table class="docs" id="show">      
    <tr class="doc" id="*Need_This*">
        <td>
            <div class="file_upload drop">
                <form class="dropzone clickable" id="*Or_Need_This*">
                </form>
            </div>
        </td>
    </tr>
</table>

Here is my jquery:

<script type="text/javascript">
$(document).ready(function(){
     $(".dropzone").dropzone({ 
        paramName: 'photos',
        url: "post.php",
        dictDefaultMessage: "Drag or Click",
        clickable: true,
        enqueueForUpload: true,
        init: function() {
            var id = $(this).closest('tr').attr('id');
            this.on("success", function(file) { alert(id); });
          }
    });
});
</script>

Right now it's returning undefined. I need to get the id's so that I can append css changes to other elements on the row. Any help is greatly appreciated!

Share Improve this question asked Apr 16, 2013 at 17:32 johnjohn 1,3304 gold badges21 silver badges34 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

this in your case refers to the Dropzone instance, not the element itself! If you need to access the actual element of your dropzone, use dropzone.element.

So you can do: var id = $(this.element).etc....

Hope that helped.

In the documentation you can read :

Gets the server response as second argument

Try with this :

this.on("success", function(file,rep) {
     alert(file);
     alert(rep); //The response
});
发布评论

评论列表(0)

  1. 暂无评论