剑道下拉列表在下拉列表中显示选项标签

kendo dropdownlist shows optionlabel in dropdown

本文关键字:下拉列表 选项 标签 显示      更新时间:2023-09-26

我正在使用kendodropdown。我使用了optionLabel="Actions",它在下拉列表中显示为一个选项,我如何在下拉列表中将其作为值忽略。

有没有一种方法,我们可以停止或隐藏选项标签在剑道下拉列表中显示为下拉列表中的一个选项。

var $dropdownElement = $("<input />");
$dropdownElement.appendTo($dropdownContainer);
$dropdownElement.kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: dropdown.items,
        optionLabel: 'Actions'
})

截至目前,Actions在下拉列表中显示为一个选项,请帮助我忽略它作为下拉列表中的值。

这是一个运行良好的解决方案,当我单击下拉菜单时,我隐藏了第一个元素。

var $dropdownElement = $("<input />");
$dropdownElement.appendTo($dropdownContainer);
$dropdownElement.kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: dropdown.items,
        optionLabel: 'Actions',
        open: function () { $($dropdownElement).getKendoDropDownList().list.find("li.k-item").first().hide(); 
                }
})

我在同一个答案中扩展了@Shashi的答案和@MarkosyanArtur的评论。每当用户尝试展开下拉列表时,open事件就会触发。为什么不使用dataBound事件?此外,一个额外的tit位,this说明符链接到ddl本身,因此;

var $dropdownElement = $("<input />");
$dropdownElement.appendTo($dropdownContainer);
$dropdownElement.kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: dropdown.items,
        optionLabel: 'Actions',
        dataBound: function () { this.element.getKendoDropDownList().list.find(".k-list-optionlabel").hide(); }
})