无法读取未定义错误的属性

时间:2017-05-29 14:03:34

标签: javascript angularjs

我正在尝试使用数组来获取特定结果,但是我得到错误无法读取未定义的属性但是当我控制台登录时,我得到的结果是我的结果是我的代码:< / p>

$mail = new PHPMailer;

我收到错误的属性是for (var j=0;j<$scope.ftListe.length;j++){ if(task[j].projet_id==id){ if(temp!=task[j].NomTache) temptache.push(task[j]); tempcol.push(lecollaborateur[j]); } temp=task[j].NomTache; } $scope.temptache=temptache; $scope.tempcol=tempcol; for(var i=0; i<temptache.length;i++){ for (var k=0;k<$scope.ftListe.length;i++){ console.log("l'id de la tache: "+temptache[i].IdTache); if(temptache[i].IdTache==$scope.ftListe[k].tacheid){ temps = temps+$scope.ftListe[k].TempsPasse; passe= passe+$scope.ftListe[k].TempsPasse * lecollaborateur[k].CoutParJour; } } tempsAr.push(temps); passeAr.push(passe); temps=0; passe=0; } ,我做错了什么?

1 个答案:

答案 0 :(得分:2)

请查看以下内容:

for(var i=0; i<temptache.length;i++){
    for (var k=0;k<$scope.ftListe.length;i++){

请注意,在内部for循环中,您会增加i变量(i++)而不是k。所以这使得i在内部循环中增加到越界偏移量。

JS运行时错误会阻止你的脚本进入无限循环 - 所以当你说明&#34;当我控制台登录相同的属性时,我得到我的结果&#34; 它实际显示结果直到您处于temptache数组的有效范围内。

您应该将其修复为:

for(var i=0; i<temptache.length;i++){
    for (var k=0;k<$scope.ftListe.length;k++){
相关问题