简体   繁体   English

kendo ui上传之前进行预处理

[英]Preprocess before kendo ui upload

I want to pass some data(a guid) to the upload method of the kendoUpload so that the particular MVC Controller action method will receive that data. 我想将一些数据(GUID)传递给kendoUpload的上载方法,以便特定的MVC Controller操作方法将接收该数据。 Each time the upload happens, I need to pass this data (guid). 每次上传时,我都需要传递此数据(引导)。

$("#propertyAttachmentUpload").kendoUpload({
            async: {
                saveUrl: fileUploadUrl,
                chunkSize: 1048576,
                removeUrl: "remove"
            },
            multiple: true,
            upload: function (e) {
                e.data = { id: $("#fileUplpderParentObjectId").val(), fileId: fileId };
            },
            showFileList: false,
            dropZone: ".propertyAttachmentDropZone",
            success: onSuccess
        });

The field is fileId . 字段是fileId I can call the above code block in a click event of the upload button and it works but the Kendo UI styles are not applied to the upload button at the initialization. 我可以在上载按钮的click事件中调用上面的代码块,它可以工作,但是Kendo UI样式在初始化时未应用于上载按钮。

$("#propertyAttachmentUpload").click(
    function() {
        var fileId = guid();
        $("#propertyAttachmentUpload").kendoUpload({
            async: {
                saveUrl: fileUploadUrl,
                chunkSize: 1048576,
                removeUrl: "remove"
            },
            multiple: true,
            upload: function (e) {
                e.data = { id: $("#fileUplpderParentObjectId").val(), fileId: fileId };
            },
            showFileList: false,
            dropZone: ".propertyAttachmentDropZone",
            success: onSuccess
        });
    });

How can I initialize the fileId without loosing the Kendo UI styles. 如何在不失去Kendo UI样式的情况下初始化fileId。

Note: I cannot call guid() inside upload method since the upload method calls for each uploading chunk. 注意:我无法在upload方法内调用guid()因为上载方法会为每个上载块调用。 For all the chunks the fileId should be same for a particular file. 对于所有块,特定文件的fileId应该相同。

I've resolved this problem using a global variable and setting that variable in the click event of the upload button, 我已经使用全局变量并在上传按钮的click事件中设置了该变量,从而解决了该问题,

var fileGuid = '';

$(document).on('click', '#propertyAttachmentUpload', function() {
    fileGuid = "";
    fileGuid = guid();
})

$("#propertyAttachmentUpload").kendoUpload({
    async: {
        saveUrl: fileUploadUrl,
        chunkSize: 1048576,
        removeUrl: "remove"
    },
    multiple: true,
    upload: function (e) {
        e.data = { id: $("#fileUplpderParentObjectId").val(), fileId: fileGuid };
    },
    showFileList: false,
    dropZone: ".propertyAttachmentDropZone",
    success: onSuccess
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM