确定 Kendo UI 控件的类型

Determine Type of Kendo UI Control

我有以下可用的实用函数(显然它只查找 5 种类型的控件,但我只使用了这些):

util.getKendoControlType = function(controlId) {
    let controlTypes = ['kendoAutoComplete','kendoMultiSelect','kendoDatePicker','kendoDropDownList','kendoNumericTextBox'];
    for(let i = 0; i < controlTypes.length; i++) {
        let control = $('#' + controlId).data(controlTypes[i]);
        if (typeof(control) !== 'undefined' && control !== null) {
            return controlTypes[i];
        }
    }
    return null;
};

我的问题:这是获取 Kendo UI 控件的控件类型的唯一方法,还是有更好的方法?

(注意:我知道我可能会抛出一个错误,而不是返回 null。)

好的!使用 kendo.widgetInstance:

util.getKendoControlType = function(controlId) {
    return kendo.widgetInstance($(`#${controlId}`)).options.name;
}

您还可以获得角色数据属性:

util.getKendoControlType = function(controlId) {
    return $(`#${controlId}`).data('role');
}