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.
我有一个kendo 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" }
];
2 个解决方案
#1
3
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”,所以需要提供days对象的value属性值。
So you just need to write value: [ "1" ]
:
所以你只需要写入值:[“1”]:
$("#days").kendoMultiSelect({
dataTextField: "text",
dataValueField: "value",
dataSource: days,
filter: "contains",
value: [ "1" ]
});
Demo JSFiddle.
演示JSFiddle。
#2
1
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()))
#1
3
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”,所以需要提供days对象的value属性值。
So you just need to write value: [ "1" ]
:
所以你只需要写入值:[“1”]:
$("#days").kendoMultiSelect({
dataTextField: "text",
dataValueField: "value",
dataSource: days,
filter: "contains",
value: [ "1" ]
});
Demo JSFiddle.
演示JSFiddle。
#2
1
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()))