我创建了以下模型,但我不明白为什么 pureComputed 可观察ApprovalIconCSS无法从其函数上下文访问 Approved() 可观察对象。
function KOViewModel() {
var self = this;
self.IsAdding = ko.observable(false);
self.IsEnabled = ko.observable(true);
self.ApprovalType = ko.observable(0);
var RowControl = function() {
return {
Approved: ko.observable(null),
ApproverNotes: ko.observable(''),
ApprovalIconCSS: ko.pureComputed(function() {
if (this.Approved() == 0)
return 'glyphicon glyphicon-remove-circle';
if (this.Approved() == 1)
return 'glyphicon glyphicon-ok-circle';
if (this.Approved() == 2)
return 'glyphicon glyphicon-time';
return '';
}, this)
};
};
self.RowControls = ko.observableArray([RowControl()]);
}
欣赏是否有人可以阐明为什么无法访问上下文。干杯!