sex
和
uniform
属性必须是可观察的,以允许双向绑定:
self.studentData = ko.observableArray([
{ rollNo: 1, sex: ko.observable(null), uniform: ko.observable(null) }
// ^^^^^^^^^^^^^^ ^ ^^^^^^^^^^^^^^ ^
// This allows the `value` binding to write to the property
]);
然后,在你的
enable
绑定时,可以使用实时更新值:
enable: sex() ? (sex().id === 2) : false
// ^^ ^^
// Because this property is now observable, you need to call it to extract
// its value
在更新的小提琴中:
https://jsfiddle.net/ocd5qvr8/