我有一個包含數字,用一個函數和一個用於循環我總結它裏面的所有的數字數組:求和陣列的JavaScript給我錯誤
$scope.selectedVoicesCss = []; //The array with numbers
$scope.TotaleCss = 0; // return me the sum of numbers
//this function populate the array
$scope.AggiornaTotaleCss = function(param,costo,index) {
if(costo){
$scope.selectedVoicesCss.push(param);
AggiornaCss();
} else{
$scope.selectedVoicesCss.splice(index,1);
}
}
//This function is for loop
function AggiornaCss(){
alert($scope.selectedVoicesCss); //it return me correct data!
for(var i = 0, n=$scope.selectedVoicesCss.length; i<n; i++) {
$scope.TotaleCss +=selectedVoicesCss[i];
}
}
似乎好了,爲什麼控制檯回到我這個錯誤?: 錯誤:沒有定義selectedVoicesCss
[I]的''而不是$ scope.TotaleCss + = selectedVoicesCss [I];'。你應該仔細看看這個錯誤,儘管這是不言自明的;) – briosheje
哇!你是對的:D –