簡體   English   中英

AngularJS 1.2.21 forEach與ng-grid不兼容嗎?

[英]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 ChromeMozilla 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM