AngularJS使用JsHint和eq运算符进行foreach循环

时间:2014-09-04 05:20:10

标签: 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;

    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

1 个答案:

答案 0 :(得分:0)

我假设您尝试禁用它的方式是在选项中使用eqeqeq: false

您可以选择尝试添加

// jshint ignore:line

在行尾

OR

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

围绕一段代码,按照docs

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