[英]Kendo UI - how do I reference a control?
Say I instantiate a Kendo control: 说我实例化一个剑道控件:
$("#files").kendoUpload({
...
})
How do I then get a reference to that control in JavaScript? 然后如何在JavaScript中获得对该控件的引用?
You have two ways to do this. 您有两种方法可以做到这一点。
Using the getKendo* method: 使用getKendo *方法:
var myUpload = $("#files").getKendoUpload(); var myUpload = $(“#files”)。getKendoUpload();
Using the Data method: 使用数据方法:
var myUpload = $("#files").data("kendoUpload"); var myUpload = $(“#files”)。data(“ kendoUpload”);
Official docs: http://docs.telerik.com/kendo-ui/intro/widget-basics/events-and-methods 官方文档: http : //docs.telerik.com/kendo-ui/intro/widget-basics/events-and-methods
To get a reference to a widget instance, use the jQuery data
method and pass the plug-in name as a string, like this : 要获取对窗口小部件实例的引用,请使用jQuery
data
方法,并将插件名称作为字符串传递,如下所示:
// Create the widget
$("#files").kendoUpload({
...
})
// retrieve the widget instance
var kendoUpload = $("#files").data("kendoUpload");
You can find more info on this at the official documentation . 您可以在官方文档中找到更多信息 。
Additionally, you can also add a whole bunch of Kendo-specific event handlers to handle events triggered by your widget : 此外,您还可以添加一堆特定于Kendo的事件处理程序,以处理您的小部件触发的事件:
function getFileInfo(e) {
return $.map(e.files, function(file) {
var info = file.name;
// File size is not available in all browsers
if (file.size > 0) {
info += " (" + Math.ceil(file.size / 1024) + " KB)";
}
return info;
}).join(", ");
}
$("#files").kendoUpload({
async: {
saveUrl: "save",
removeUrl: "remove",
autoUpload: true
},
cancel: function(e) {
kendoConsole.log("Cancel :: " + getFileInfo(e));
},
complete: function onComplete(e) {
kendoConsole.log("Complete");
},
error: function(e) {
kendoConsole.log("Error (" + e.operation + ") :: " + getFileInfo(e));
},
progress: function(e) {
kendoConsole.log("Upload progress :: " + e.percentComplete + "% :: " + getFileInfo(e));
},
remove: function(e) {
kendoConsole.log("Remove :: " + getFileInfo(e));
},
select: function(e) {
kendoConsole.log("Select :: " + getFileInfo(e));
},
success: function(e) {
kendoConsole.log("Success (" + e.operation + ") :: " + getFileInfo(e));
},
upload: function(e) {
kendoConsole.log("Upload :: " + getFileInfo(e));
}
});
You can find a fully working demo at the official documentation . 您可以在官方文档中找到可以正常运行的演示 。
I now do this to get the files array of the upload control: 我现在这样做来获取上载控件的文件数组:
var logoUploader = $('#files').data('kendoUpload');
var files = logoUploader.options.files;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.