【问题标题】:kendo dropdownlist shows optionlabel in dropdownkendo 下拉列表在下拉列表中显示选项标签
【发布时间】:2016-01-28 21:37:00
【问题描述】:

我正在使用 kendodropdown。我使用了 optionLabel = "Actions",它在下拉菜单中显示为一个选项,我该如何忽略它作为下拉菜单中的一个值。

有没有一种方法可以让我们停止或隐藏 kendo 下拉列表中的 optionLabel 以在下拉列表中显示为选项。

var $dropdownElement = $("<input />");

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

到目前为止,操作在下拉列表中显示为一个选项,请帮助我将其作为下拉列表中的值忽略。

【问题讨论】:

  • (据我所知)这是下拉列表的默认功能,我们无法更改。

标签: javascript angularjs kendo-ui kendo-dropdown


【解决方案1】:

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

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(); 
                }
})

【讨论】:

  • 最好隐藏类“k-list-optionlabel”的元素,而不是第一个元素。它有单独的类
【解决方案2】:

我从@Shashi 的答案和@MarkosyanArtur 在同一答案中的评论延伸。每次用户尝试展开 DropDown 列表时都会触发 open 事件。为什么不使用dataBound 事件呢?此外,还有一个额外的提示,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(); }
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-04
    • 1970-01-01
    • 2020-07-17
    • 2017-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多