当$scope.event
到达BufferLimit时,我将从数组中删除第一个元素,这将减少totalReceived
值,而不是我在if语句之外推送新元素,但是当我推送新元素时,我不会将其视为最后一个数组中的项目?我还使用slice
冻结我的浏览器在bufferlimit shift
,它与slice
相同。我正在寻找更好的解决方案,因为数据量很大?
Ctrl.js
//BufferLimit is 8MB totalReceived value is coming from other method
$scope.event = [];
function safelyAdd(element) {
if (totalReceived > Bufferlimit && $scope.event.length) {
$scope.event = $scope.event.splice(1); //delete first element in $scope.event
totalReceived -= $scope.event[0].messageSize; //total message size minus deleted message size
console.log('totalReceivedBytes', totalReceived);
// $scope.event =[];//reset array if max size reached..
console.log('$scope.event', $scope.event)
}
console.log('$scope.event.length', $scope.event.length);
$scope.event.push(element); //then push new item..
}
答案 0 :(得分:0)
$('#Metric_x0020_Name').css('width', '602px');
如下 $ scope.event.splice(1); //删除$ scope.event中的第一个元素