名称+复选框的单向绑定工作正常,但它最初不适用于单选按钮employeeTypeA,尽管它在viewmodel中的值为true,html显示单选按钮未设置,为什么会这样?
<script type="text/javascript">
$(function()
{
var PersonViewModel = function()
{
this.firstName = ko.observable('Lisa');
this.lastName = ko.observable('T');
this.isCustomer = ko.observable(true);
this.employeeTypeA = ko.observable(true);
this.employeeTypeB = ko.observable(false);
};
var personViewModel = new PersonViewModel();
ko.applyBindings(personViewModel, $('data').get(0));
});
</script>
<div id="data">
<span data-bind="text: firstName"></span>
<span data-bind="text: lastName"></span>
<input type="checkbox" data-bind="checked: isCustomer" title="Is a customer" />
<input name="x" type="radio" data-bind="checked: employeeTypeA" title="Employee type A" />
<input name="x" type="radio" data-bind="checked: employeeTypeB" title="Employee type B" />
</div>