【问题标题】:$(this) not working on Kendo file upload$(this) 不适用于剑道文件上传
【发布时间】:2016-12-09 09:45:23
【问题描述】:

我的剑道网格中有剑道上传控件作为列之一。请在下面的栏目中找到:

$(".files").kendoUpload({
    async: {
        saveUrl: "/api/test/test/test",
        removeUrl: "/api/test/test/test",
        autoUpload: true
    },
    success: onSuccess,
             multiple:false,
             error: onError,
             showFileList: true,
             validation: {
                 allowedExtensions: [".pdf", ".xlsx", ".docx", ".rtf", ".tif",".txt"],MaxFileSize:5242880
             }
});

行模板:

 template: '<div class="small-12 attachment-wrapper columns"><div class="row"><div class="small-11 columns"><textarea placeholder="Enter notes and descriptions here for claims that have been closed"></textarea></div></div><div class="row"><div class="small-6 attachment columns"><div class="demo-section k-content"><input name="files" class="files" id="files" type="file" /><span class=success></span></div></div></div>'

我正在尝试使用从成功的文件上传获得的结果更新最近的跨度。

function onSuccess(e) {
    alert(e.response.FileName);

    $(this).closest('span .success').text(e.response.FileName);
}

但我无法找到 span ,它总是说 undefined 。我认为 $(this) 不适用于 kendo controls 。 当我对按钮执行相同的操作时,它确实有效。如何使用 jquery 获取上传控件的上下文和最近跨度

请对此提出建议

【问题讨论】:

    标签: jquery file kendo-ui upload


    【解决方案1】:

    在这种情况下,“this”不是对 Upload 小部件的 DOM 元素的引用,而是对 Upload 小部件/类本身的引用。

    试试

    this.wrapper.closest(...)
    

    改为。

    【讨论】:

      【解决方案2】:

      我从另一个帖子中找到了答案:

      Check here

      this.element.context.closest('td') 
      

      然后我们可以获取列的 jquery 对象的引用,我们可以从中轻松定位跨度。

      希望这对其他人有所帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-03-29
        • 2016-06-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多