0

net mvc,我想根据一些使用javascript动态地设置Kendo Multiselect的MaxSelectedItems属性。请参阅下面的代码片段。提前致谢。

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

在我的 javascript

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

JS 不工作

4

2 回答 2

3

尝试做:

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>

于 2014-10-10T09:37:18.987 回答
0
 @(Html.Kendo().MultiSelect()
            .Name("ArenaList2")
            .Placeholder("Select attendees...")
            .BindTo(Model.ArenaList)
            .DataTextField("Text")
            .DataValueField("Value")
            .MaxSelectedItems(3)
 )

您可以使用此选项在控件本身中配置它 .MaxSelectedItems(3)

于 2016-03-17T12:43:54.980 回答