javascript 在 KENDO UI Multiselect 中选择默认值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17894659/
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
Selecting default values in KENDO UI Multiselect
提问by ckv
I have a kendo UI multiselect input. I am populating the values with a JSON object. I want the first value to be selected. Based on the documenation I have given as below but the value is still not selected.
我有一个剑道 UI 多选输入。我正在用 JSON 对象填充值。我想选择第一个值。根据我给出的文档如下,但仍未选择该值。
$("#days").kendoMultiSelect({
dataTextField: "text",
dataValueField: "value",
dataSource: days,
filter: "contains",
value: [
{ text: "First", value: "1" },
]
});
var days = [
{ text: "First", value: "1" },
{ text: "Second", value: "2" },
{ text: "Third", value: "3" },
{ text: "Fourth", value: "4" },
{ text: "Fifth", value: "5" }
];
采纳答案by nemesv
Because you have configured the dataValueField: "value"
in the value
array you need to provide the value
property values of the days objects.
因为您已经dataValueField: "value"
在value
数组中配置了,所以您需要提供value
days 对象的属性值。
So you just need to write value: [ "1" ]
:
所以你只需要写value: [ "1" ]
:
$("#days").kendoMultiSelect({
dataTextField: "text",
dataValueField: "value",
dataSource: days,
filter: "contains",
value: [ "1" ]
});
Demo JSFiddle.
回答by LawMan
In case you are using server side binding, you can do this...
如果您使用服务器端绑定,您可以这样做...
@(Html.Kendo().MultiSelect()
.Name("RolesVisibleToMultiSelect")
.Placeholder("Select Roles...")
.DataValueField("RoleId")
.DataTextField("RoleName")
.BindTo(Model.RequestDiscussion.RolesVisibleTo)
.Value(Model.RequestDiscussion.RolesVisibleTo.Select(r => r.RoleId).ToArray()))