[英]AngularJS 1.2.21 forEach is not compatible with ng-grid?
AngularJS 1.2.21中是否存在与forEach相关的bug ,而AngularJS 1.2.20中没有该bug?
我测试了以下代码(加载ng-grid时):
var contor = 0;
$scope.$watch('gridOptions.$gridScope.columns', functionForColumnsChange, true);
...
function functionForColumnsChange(newv, oldv) {
if ( newv !== oldv ) {
console.log(contor++);
}
}
如果我使用:
https://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular.js
输出是
0
但是如果我使用
https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js
输出是
TypeError:无法在Object.forEach( https://ajax.googleapis)上http://angular-ui.github.io/ng-grid/lib/ng-grid.js:1668:36设置未定义的属性'sortPriority' .com / ajax / libs / angularjs / 1.2.21 / angular.js:325:18 )的self.sortData( http://angular-ui.github.io/ng-grid/lib/ng-grid.js: 1667:25 )在self.sortColumnsInit( http://angular-ui.github.io/ng-grid/lib/ng-grid.js:1701:18 )在Object.ngGridDirectives.directive.ngGridDirective.compile.pre。 grid.init.then.dataWatcher [as fn]( http://angular-ui.github.io/ng-grid/lib/ng-grid.js:2943:42 )在Scope。$ get.Scope。$ digest ( https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:12471:29 )在Scope。$ get.Scope。$ apply( https://ajax.googleapis.com/ ajax / libs / angularjs / 1.2.21 / angular.js:12736:24 ), 网址为https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:1438:15(位于Object.invoke) ( https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.js:3940:17 )在doBootstrap( https://ajax.googleapis.com/ajax/libs/angularjs/1.2。 21 / angular.js:1436:14 )
0
1
为什么会出错? 为什么1在0之后?
如果我更改ng-grid.js的注释两行:
//c.sortPriority = i + 1;
//push(c);
错误消息不再存在,但是有“ 1”。
所使用的ng-grid来源于以下来源: http : //angular-ui.github.io/ng-grid/lib/ng-grid.js (缩小版也存在相同的问题)。
以后的编辑:问题似乎与此问题有关: https : //github.com/angular/angular.js/commit/36625de0d3ebc1fc091af474d942c6ce16b0a1c0
区别仅在于Google Chrome和Mozilla Firefox 。
在IE8中,两个版本的AngularJS均输出0和1。 IE8中的输出:
TypeError:“未定义”为null或不是对象
0
1
问题是我有一个错误的$scope.sortInfo
数组:
$scope.sortInfo = {fields: ["N", "A", "B", "C"], directions: ['asc']};
即使此时“ N”不是一列。
我发现了3种可能的解决方案:
1) 更改 数组 :
$scope.sortInfo = {fields: ["A", "B", "C"], directions: ['asc']};
2)将ng-grid 更改为更宽松:
if ( typeof c !== 'undefined' ) {
c.sortPriority = i + 1;
push(c);
}
3)将AngularJS 更改为更宽松:
for (key = 0; key < obj.length; key++) {
if ( typeof obj[key] !== 'undefined' ) {
iterator.call(context, obj[key], key);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.