我正在使用 KnockoutJS 来显示用户列表。在同一页面上,一个链接会触发一个影子框模式窗口。当用户关闭模式时,我希望刷新用户列表。我已经有了 Shadowbox 模式触发的回调函数,但是如何让它刷新用户列表呢?
function User(data) {
this.firstname = ko.observable(data.firstname);
this.lastname = ko.observable(data.lastname);
this.fullname = ko.computed(function () {
return this.firstname() + " " + this.lastname();
}, this);
this.userfunctions = ko.observable(data.userfunctions);
this.phonework = ko.observable(data.phonework);
this.phonemobile = ko.observable(data.phonemobile);
this.email = ko.observable(data.email);
this.editurl = ko.observable(data.editurl);
}
function UserListViewModel() {
var self = this;
self.users = ko.observableArray([]);
self.users.loading = ko.observable(false);
self.users.loading(true);
$.getJSON("/UserJSON.ashx", {
requestType: "userList",
pageId: '12',
companyId: '1'
},
function (allData) {
var mappedUsers = $.map(allData, function (item) { return new User(item); });
self.users(mappedUsers);
self.users.loading(false);
});
}
ko.applyBindings(new UserListViewModel());