2013-07-27 141 views
4

我有一個kendo UI多選輸入。我正在用JSON對象填充值。我想要選擇第一個值。基於以下給出的文檔,但該值仍未被選中。在KENDO UI Multiselect中選擇默認值

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

      ]; 

回答

3

因爲你有value陣列中配置的dataValueField: "value"您需要提供天對象的value屬性值。

所以,你只需要編寫value: [ "1" ]

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

演示JSFiddle.

+0

poahr,很感謝這! – chris

1

如果您正在使用服務器端的結合,你可以做到這一點...

@(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()))