最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Selecting default values in KENDO UI Multiselect - Stack Overflow

programmeradmin2浏览0评论

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.

$("#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" }

            ];

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.

$("#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" }

            ];
Share Improve this question edited Jul 27, 2013 at 6:47 nemesv 140k16 gold badges423 silver badges362 bronze badges asked Jul 27, 2013 at 5:38 ckvckv 10.8k20 gold badges102 silver badges152 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Because you have configured the dataValueField: "value" in the value array you need to provide the value property values of the days objects.

So you just need to write value: [ "1" ]:

$("#days").kendoMultiSelect({
                dataTextField: "text",
                dataValueField: "value",
                dataSource: days,
                filter: "contains",
                value: [ "1" ]
});

Demo JSFiddle.

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()))
发布评论

评论列表(0)

  1. 暂无评论