私はこれについてSOを検索しましたが、明らかなものは見つかりませんでした。私はジョブのダッシュボードを持っており、そのステータスは 1 日を通して継続的に変化します。データベースで更新コマンドを実行して、概念実証アプリケーションをまとめ、手動で更新をトリガーしようとしています。これは私が設定したものですが、更新を実行すると、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();
});
});
});