大家好,我有一个Singalr,MVC5,Knockoutjs,jQuery Datatables项目,用于自动更新数据。但是,我遇到了一个巨大的问题,内存大小不断增长,永远不会释放,如图所示。
这是我的代码我已经在我的桌子上敲了几天,我甚至尝试将其转换为完整的视图模型。有任何帮助,请:(
所以我做了一些建议的更改,但现在表格没有重新绘制任何数据,内存仍在增长,我在这里做错了。
//更新了代码
function loadAlerts(newAlerts, alertsObservable) {
alertsObservable([]);
var alerts = [];
alerts = newAlerts;
alertsObservable(alerts);
$('#alarmsTable').DataTable().clear().draw();
}
function AlertsViewModel() {
var self = this;
self.hub = $.connection.alarmsHub;
self.alarms = ko.observableArray();
self.activate = function (alertsObservable) {
alertsObservable([]);
self.hub.server.getAllAlarms().done(pass).fail(failure);
function pass(data) {
var alerts = [];
alerts = data;
alertsObservable(alerts);
console.log('Passed: SignalR will begin, refresh is sent every 1 min.');
loadDataTable(alerts);
}
function failure() {
console.log('Something happened, the query to the database failed.');
}
};
self.hub.client.updateAlarms = function (broadCastAlarms) {
loadAlerts(broadCastAlarms, vm.alarms);
console.log('Broadcaseted Changes');
};
self.refresh = function () {
vm.activate(vm.alarms);
}
}
var vm = new AlertsViewModel();
ko.applyBindings(vm);
$.connection.hub.start({ transport: 'longPolling' }, function () { vm.activate(vm.alarms) });
//Let's put back any values we stored to the input boxes
var cookies = $.cookie();
for (var name in cookies) {
$('input[name="' + name + '"]').val(cookies[name]);
}
});