我有一个jQuery对话框,用户可以在页面之间切换。问题是视图模型会记住最后显示的页面 - 如果我打开对话框,导航到第2页并关闭它,如果我再次重新打开对话框,它将保留在第2页。
每次打开视图模型时如何重置视图模型?
JobActivity = function() {
var self = this;
// This is the array i am putting the data in from ajax call
self.arraytoadd = ko.observableArray();
self.currentPage = ko.observable(1);
self.perPage = 5;
self.pagedItems = ko.computed(function() {
self.dummy();
var pg = this.currentPage(),
start = this.perPage * (pg - 1),
end = start + this.perPage;
return self.arraytoadd().slice(start, end);
}, this);
self.nextPage = function() {
if (self.nextPageEnabled()) this.currentPage(this.currentPage() + 1);
};
self.previousPage = function() {
if (this.previousPageEnabled()) this.currentPage(this.currentPage() - 1);
};
self.nextPageEnabled = ko.computed(function() {
return this.arraytoadd().length > this.perPage * this.currentPage();
}, this);
self.previousPageEnabled = ko.computed(function() {
return this.currentPage() > 1;
}, this);
}