【问题标题】:django-ajax-uploader: get the clicked element on upload successdjango-ajax-uploader:上传成功时获取点击的元素
【发布时间】:2016-05-03 16:27:26
【问题描述】:

我正在使用 django-ajax-uploader 通过 Ajax 上传文件: https://github.com/skoczen/django-ajax-uploader.

上传成功后,我想获取点击的元素。 代码如下:

$('.file-uploader').each(function()
{
    input_element=$(this);

    var uploader = new qq.FileUploader(
    {
        action: "{% url 'campaigns:my_ajax_upload' %}" ,
        element: input_element[0],
        multiple: false,
        onComplete: function(id, fileName, responseJSON) 
        {
            ...
        },
        onAllComplete: function(uploads) 
        {
            ...
            //how to get the element that triggered the upload?
        },
    });
});

这里的问题是同一页面中有很多file-uploader元素,所以如果我使用input_element获取触发上传的点击按钮,我只会得到最后加载的按钮!

提前谢谢你。

【问题讨论】:

    标签: jquery ajax django file upload


    【解决方案1】:

    刚刚找到答案,你可以bindonAllComplete,这样你就可以在callback方法中使用this

    onAllComplete: function(uploads) 
    {
           window.console&&console.log("All complete!");
           //this is accessible and binded to the right object
           $(this).closest(".show_hide") ... ;
    }.bind(this),
    

    我在另一篇 SO 帖子中找到了答案: https://stackoverflow.com/a/30797378/1875861

    【讨论】:

      猜你喜欢
      • 2021-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-02
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      相关资源
      最近更新 更多