我对此进行了搜索,但没有发现任何明显的东西。我有一个作业仪表板,它们的状态在一天中不断变化,我试图将一些概念证明应用程序放在一起,并通过在数据库中运行更新命令手动触发更新。这是我设置的,但是当我执行更新时,我没有看到 UI 有任何变化,你能看到我哪里出错了吗?
中心:
public class DashboardHub : Hub
{
private readonly Repository _repository;
public DashboardHub()
{
_repository= new Repository();
}
public void GetJobs()
{
var jobs = _repository.GetJobs();
Clients.All.allJobsRetrieved(jobs);
}
}
淘汰赛视图模型
$(function () {
$(function () {
function jobViewModel(id, name, isPaused, currentStatus, cob, owner) {
this.hub = $.connection.dashboardHub;
//job variables, initialised from params
this.Id = id;
this.Name = ko.observable(name);
this.IsPaused = ko.observable(isPaused);
this.CurrentStatus = ko.observable(currentStatus);
this.Cob = ko.observable(cob);
}
function dashboardViewModel() {
this.hub = $.connection.dashboardHub;
//jobs collection
this.jobs = ko.observableArray([]);
//reference to jobs collection
var jobs = this.jobs;
//load jobs, calling server side hub method
this.init = function () {
this.hub.server.getJobs();
};
//callback from server side hub sending jobs to client
this.hub.client.allJobsRetrieved = function (allJobs) {
var mappedJobs = $.map(allJobs, function (job) {
return new jobViewModel(job.Id, job.Name, job.IsPaused, job.CurrentStatus, job.CoB, self);
});
jobs(mappedJobs);
};
//callback from server side hub sending error messages to client
this.hub.client.raiseError = function (error) {
$("#error").text(error);
};
}
//set up the viewmodel
var viewModel = new dashboardViewModel();
ko.applyBindings(viewModel);
//call to initialise
$.connection.hub.start(function () {
viewModel.init();
});
});
});