2014-09-04 44 views
0

我从咕噜我JSHint一个错误,它沿行云:使用AngularJS foreach循环与JsHint和EQ操作

line 48 col 23 Expected '===' and instead saw '=='. 

“===”打破了代码。

我有谷歌周围,显然禁用此被打破的选项(使用最新版本4日,2014年9月)

我的代码都这样:

$scope.getStationById = function(stationId) 
{ 
    var parsedId = stationId, 
    foundStation; 

    angular.forEach($scope.stations, function(station) 
    { 
     if(station.id == parsedId) 
     { 
      foundStation = station; 
     } 
    }); 

    return foundStation; 
}; 

如何任何建议我可以沉默这个恼人的错误?

编辑

的控制台登录:

console.log(station.id + " | " + parsedId); 

产地:

1 | 1 
3 | 1 
5 | 1 
+0

检查两个操作数的类型。他们不能是一样的。 – elclanrs 2014-09-04 05:22:47

+0

添加以下日志语句,并告诉输出是什么,console.log(typeof station.id); console.log(typeof parseId)。我认为一个是字符串,其他是数字 – coder 2014-09-04 05:25:57

回答

0

我假设你想禁用它使用在选项eqeqeq: false的方式吗?

什么你可以尝试作为替代被添加

// jshint ignore:line 

在生产线

OR

/* jshint ignore:start */ 
... 
/* jshint ignore:end */ 

周围的代码块结束时,按该docs

最好的方法仍然可能是修复代码,以便它不必依赖于类型强制功能。您可以使用parseInt(str, 10)

+0

我试过// jshint忽略:行被忽略。 – 2014-09-04 05:44:29

+0

虽然第二块代码工作,多行块忽略。 – 2014-09-04 21:53:51