Javascript 带JsHint和eq运算符的AngularJS foreach循环
我从Grunt得到的JSHint有一个错误,大致如下:Javascript 带JsHint和eq运算符的AngularJS foreach循环,javascript,angularjs,gruntjs,jshint,Javascript,Angularjs,Gruntjs,Jshint,我从Grunt得到的JSHint有一个错误,大致如下: line 48 col 23 Expected '===' and instead saw '=='. 使用“==”会中断代码 我在谷歌上搜索过,显然禁用此功能的选项已被破坏(使用2014年9月4日的最新版本) 我的代码是这样的: $scope.getStationById = function(stationId) { var parsedId = stationId, foundStation; angu
line 48 col 23 Expected '===' and instead saw '=='.
使用“==”会中断代码
我在谷歌上搜索过,显然禁用此功能的选项已被破坏(使用2014年9月4日的最新版本)
我的代码是这样的:
$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
我假设您试图禁用它的方式是在选项中使用
eqeq:false
作为替代方案,您可以尝试添加
// jshint ignore:line
在队伍的尽头
或
围绕一块代码,如
最好的方法可能仍然是修复代码,这样它就不必依赖类型强制来工作。您可以为此使用
parseInt(str,10)
。检查两个操作数的类型。它们不能相同。添加以下日志语句并告诉输出,console.log(typeof station.id);log(parseId的类型)。我认为一个是字符串,另一个是数字。不过,第二段代码可以工作,多行块忽略。
/* jshint ignore:start */
...
/* jshint ignore:end */