这是您的版本:
function StudentViewModel() {
var self = this;
this.students = ko.observableArray([]);
this.detailedStudent = ko.observable();
this.clickMe = function(student) {
alert(student.IncludeInStudentSiteResults());
self.detailedStudent(student);
alert(student.IncludeInStudentSiteResults());
}
}
尝试使用我的版本:
function StudentViewModel() {
var self = this;
this.students = ko.observableArray([]);
this.detailedStudent = ko.observable();
this.clickMe = function(student) {
alert(student.IncludeInStudentSiteResults());
self.detailedStudent(ko.observable(student));
alert(student.IncludeInStudentSiteResults());
}
}
的jsfiddle:http://jsfiddle.net/62fDB/23/
这当然是有帮助的,并且朝着正确的方向迈出了一步,但布尔值会自动作为布尔值序列化为JSON。有布尔值作为下拉选项值的首选方法吗? –
这可能有助于[Knockoutjs(版本2.1.0):绑定布尔值来选择框](http://stackoverflow.com/questions/10510683/knockoutjs-version-2-1-0-bind-boolean-value-to - 选择框) –