簡體   English   中英

$(this)不適用於Kendo文件上傳

[英]$(this) not working on Kendo file upload

我在kendo網格中將kendo上傳控件作為列之一。 請在下面的列中找到:

$(".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);
}

但是我無法找到范圍,它總是說undefined。 我認為$(this)在kendo控件上不起作用。 當我對按鈕執行相同的操作時,它確實起作用。 如何使用jquery獲取上載控件的上下文和最接近的跨度

請對此提出建議

在這種情況下,“ this”不是對Upload小部件的DOM元素的引用,而是對Upload小部件/類本身的引用。

嘗試

this.wrapper.closest(...)

代替。

我從其他帖子中找到了答案:

在這里檢查

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

然后,我們可以引用該列的jquery對象,從中可以輕松地找到范圍。

希望這對其他人有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM