javascript Angular + Kendo:下拉列表的默认占位符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25633065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 04:46:17  来源:igfitidea点击:

Angular + Kendo: Default placeholder for drop down list

javascriptangularjskendo-uitelerikkendo-dropdown

提问by Alan Souza

I was wondering how to set placeholder for drop down list in kendo ui + angular.

我想知道如何在 kendo ui + angular 中为下拉列表设置占位符。

Currently I have:

目前我有:

Template

模板

<select kendo-drop-down-list ng-model="selectedElement" k-options="options" >
</select>

Controller

控制器

...
$scope.options = {
        dataTextField: 'label',
        dataValueField: 'id',
        dataSource: {
            data: [
                {
                    "label": "Please Select..."
                },
                {
                    "id": "linear",
                    "label": "Sample Linear"
                },
                {
                    "id": "bar",
                    "label": "Sample Bar"
                }
            ]
        }
    };
...

If I replace the datasource by a backend call, I cannot have 'Please Select' there. Is there another way of solving this problem?

如果我通过后端调用替换数据源,则无法在此处显示“请选择”。有没有其他方法可以解决这个问题?

I tried using data-option-label="Please Select"following instructions in this link, but no luck.

我尝试按照此链接中的说明使用data-option-label="Please Select",但没有成功。

回答by George K

Well, you can either define it as a dataattribute (more information here)

好吧,您可以将其定义为数据属性(此处有更多信息

Template

模板

<select kendo-drop-down-list k-option-label="'item1'" ng-model="selectedElement" k-options="options" >
</select>

or set the optionLabeloption in the $scope

或在 $scope 中设置optionLabel选项

Controller

控制器

...
$scope.options = {
    optionLabel: "Item...",
    dataTextField: 'label',
    dataValueField: 'id',
    dataSource: {
        data: [
            {
                "label": "Please Select..."
            },
            {
                "id": "linear",
                "label": "Sample Linear"
            },
            {
                "id": "bar",
                "label": "Sample Bar"
            }
        ]
    }
};

...

...