我想使用带有淘汰视图模型的映射插件:
var TasksListViewModel = (function () {
var self = this;
var GET_PATH = "/Tasks/Index";
self.loadData = function() {
$.getJSON(GET_PATH, function (data) {
ko.mapping.fromJS(data, {}, self);
setSubscribers();
setComputed();
ko.applyBindings(self);
});
};
self.updateData = function() {
$.getJSON(GET_PATH,
{
page: self.Page()
}, function (data) {
ko.mapping.fromJS(data, TasksListViewModel);
});
};
self.setSubscribers = function() {
self.Page.subscribe(function (newPage) {
self.updateData();
});
};
self.setComputed = function () {
self.TotalPages = ko.computed(function () {
return Math.ceil(self.Total() / self.PageSize());
});
}
return self;
}());
但是我只能在映射后声明订阅者和计算的 observables。这是正确的方法吗?