我通过自定义绑定使用了knockup.js的fineuploader控件。
这是我的代码:
ko.bindingHandlers.contractuploader = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
$(element).fineUploader({
request: {
endpoint: '/UploadContract/UploadFile/',
params: valueAccessor(),
validation: {
allowedExtensions: ['doc', 'docx', 'pdf']
},
callbacks: {
onSuccess: function () {
},
onError: function (id, name, reason, xhr) {
toastr.error(reason);
}
}
},
button: $(".my-custom-class")
}).on('complete', function (event, id, fileName, responseJSON) {
if (responseJSON.success) {
}
});
},
update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
// This will be called once when the binding is first applied to an element,
// and again whenever the associated observable changes value.
// Update the DOM element based on the supplied values here.
}
};
我注意到jquery.fineuploader-4.2.1.js
$.fn.fineUploader = function(optionsOrCommand) {
}
但我想使用基本功能,以便我将其指向锚点:
<div class="upload-button-div">
<a data-bind="contractuploader : { 'jobId': JobId }">Upload a File</a>
</div>
我不想要控件附带的所有额外功能。只是一个链接打开文件选择窗口,然后将文件上传到端点。