如何在Javascript中动态设置kendo Multiselect的MaxSelectedItems属性

时间:2014-10-10 08:40:51

标签: kendo-ui kendo-asp.net-mvc kendo-multiselect

net mvc,我想基于一些动态使用javascript动态设置Kendo Multiselect的MaxSelectedItems属性。请参阅下面的代码片段。在此先感谢。

@ Html.Kendo()。MultiSelectFor(model => model.Name)

在我的javascript中

if(condition)
{    
    $(#Name).MaxSelectedItems(1);
}

JS无法正常工作

2 个答案:

答案 0 :(得分:2)

尝试做:

if (condition) {
    var ms = $("#multiselect").data("kendoMultiSelect");
    ms.options.maxSelectedValue = 6;
}

示例:



$("#required").kendoMultiSelect({
  maxSelectedItems : 4
}).data("kendoMultiSelect");

$("#change6").on("click", function() {
  var sel = $("#required").data("kendoMultiSelect");
  sel.options.maxSelectedItems = 6;
}); 
$("#change4").on("click", function() {
  var sel = $("#required").data("kendoMultiSelect");
  sel.options.maxSelectedItems = 4;
});

<link href="http://cdn.kendostatic.com/2014.2.1008/styles/kendo.default.min.css" rel="stylesheet"/>
<link href="http://cdn.kendostatic.com/2014.2.1008/styles/kendo.common.min.css" rel="stylesheet"/>
<script src="http://cdn.kendostatic.com/2014.2.1008/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.2.1008/js/kendo.all.min.js"></script>

<button id="change6" class="k-button">Change to 6</button><br/>
<button id="change4" class="k-button">Change to 4</button><br/>
<select id="required" multiple="multiple" data-placeholder="Select attendees...">
  <option>Steven White</option>
  <option>Nancy King</option>
  <option>Nancy Davolio</option>
  <option>Robert Davolio</option>
  <option>Michael Leverling</option>
  <option>Andrew Callahan</option>
  <option>Michael Suyama</option>
  <option selected>Anne King</option>
  <option>Laura Peacock</option>
  <option>Robert Fuller</option>
  <option>Janet White</option>
  <option>Nancy Leverling</option>
  <option>Robert Buchanan</option>
  <option>Margaret Buchanan</option>
  <option selected>Andrew Fuller</option>
  <option>Anne Davolio</option>
  <option>Andrew Suyama</option>
  <option>Nige Buchanan</option>
  <option>Laura Fuller</option>
</select>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

 @(Html.Kendo().MultiSelect()
            .Name("ArenaList2")
            .Placeholder("Select attendees...")
            .BindTo(Model.ArenaList)
            .DataTextField("Text")
            .DataValueField("Value")
            .MaxSelectedItems(3)
 )

您可以使用此选项 .MaxSelectedItems(3)

在控件中配置它