我正在尝试绑定来自kendo observable的复选框选中的值。所有在线示例都在声明性语法中显示data-bind属性,如:
<div class="demo-section k-content wide">
<input type="checkbox" value="Apple" data-bind="checked: isSelected" />
</div>
<script>
var viewModel = kendo.observable({
isSelected: false,
});
kendo.bind($("div.demo-section"), viewModel);
</script>
如何绑定(或添加数据绑定)
@Html.Kendo().CheckBoxFor(m => m.data).HtmlAttributes(new {@class="chkbox"})
使用kendo observable检查值?
我试过了:
$(".chkbox").kendoCheckBox({ //does kendoCheckBox even exist?
checked: viewModel.isSelected
})
和kendo.CheckBoxFor只接受一个参数,所以我不能这样做:
@Html.CheckBoxFor(m => m.data, new { data_bind = "checked:isSelected" });
答案 0 :(得分:2)
将“data_bind:whatever”添加到Kendo.CheckBoxFor()的HtmlAttributes匿名对象,即
@Html.Kendo().CheckBoxFor(m => m.data).HtmlAttributes(new {@class="chkbox", data_bind = "checked: isSelected"})
我已多次这样做了:
<div id="checkBoxDiv">
@Html.Kendo().CheckBoxFor(m => m.BooleanField).HtmlAttributes(new { data_bind = "checked: isBooleanFieldSelected" })
@Html.Kendo().CheckBoxFor(m => m.OtherBooleanField).HtmlAttributes(new { data_bind = "checked: isOtherBooleanFieldSelected" })
</div>
<script>
var model = kendo.observable({
isBooleanFieldSelected: true,
isOtherBooleanFieldSelected: false
});
kendo.bind($("#checkBoxDiv"), model);
</script>