我有一个关于敲除的问题,这是我的 HTML 和 Javascript 代码,你能告诉我我的代码有什么问题吗,当我点击复选框时,相关的 isWaived 未选中
<input type="checkbox" data-bind="checked: isWaived(0)">
<div data-bind="visible: isWaived(0)" >
<div class="alert">
You have waived coverage for this member0.
</div>
</div>
这是我的 javascript 代码
function Member(idx, isWaived) {
var self = this;
self.idx = idx;
self.isWaived = ko.observable(isWaived);
}
function ReviewCartViewModel() {
var self = this;
// Editable data
self.members = ko.observableArray([
new Member(0, true),
new Member(1, false),
new Member(2, false),
new Member(3, false),
]);
self.isWaived = function (idx) {
for (var i in self.members()) {
var member = self.members()[i];
if (member.idx == idx)
return member.isWaived();
}
};
self.DoWave = function (idxs) {
for (var i in self.members()) {
var member = self.members()[i];
if (member.idx == idxs) {
member.isWaived(!member.isWaived());
//Send Ajax Request to waived the user
}
}
};
}
ko.applyBindings(new ReviewCartViewModel());
这是这个脚本的小提琴页面 http://jsfiddle.net/mohsenvafa/spMvd/