0
我想簡單地將計算出的可觀察性添加到映射的對象。我想避免添加父視圖模型。我試過使用映射的選項創建,但似乎沒有工作。如何將計算的觀察值添加到映射視圖模型?
$.getJSON(apiUrl, function (data) {
var mappingOptions = {
// overriding the default creation/initialization code
create: function (options) {
ko.mapping.fromJS(options.data, {}, this);
// setup the computed binding
this.FullNameComputed= ko.computed(function() {
return this.FirstName() + this.LastName();
}, this);
}
};
ko.mapping.fromJS(data, mappingOptions, self.Users);
}