javascript - ag-grid + templateUrl 在 IE9 中崩溃

标签 javascript angularjs internet-explorer ag-grid

我刚刚实现了ag-grid,但发现当使用带有 Angular 编译模板的cellTemplates时,IE9会崩溃。

你们中有人遇到过这种情况并且可能找到了解决方法吗?

如何重现:

使用 IE 前往此处 ( http://www.ag-grid.com/angular-grid-cell-template/index.php ),然后从 DevTools 中选择 IE9。

由于 Angular 编译模板,它会崩溃。不知道我能做些什么。

(我还在 GitHub 上就此问题提出了一个问题: https://github.com/ceolter/ag-grid/issues/521 )

编辑:

调试它,有一个无限循环,因为从一个方法对数组的更新,以某种方式对另一种方法不可见......

无限循环是: getTemplate,(排队等待直到调用结束),调用结束,模板添加到缓存,运行回调,回调在templateCache中没有看到模板,创建另一个回调,将其添加到队列中,等等。 (代码来自下面的ag-grid)。

// returns the template if it is loaded, or null if it is not loaded
        // but will call the callback when it is loaded
        TemplateService.prototype.getTemplate = function (url, callback) {
            var templateFromCache = this.templateCache[url];
            if (templateFromCache) {
                return templateFromCache;
            }
            var callbackList = this.waitingCallbacks[url];
            var that = this;
            if (!callbackList) {
                // first time this was called, so need a new list for callbacks
                callbackList = [];
                this.waitingCallbacks[url] = callbackList;
                // and also need to do the http request
                var client = new XMLHttpRequest();
                client.onload = function () {
                    that.handleHttpResult(this, url);
                };
                client.open("GET", url);
                client.send();
            }
            // add this callback
            if (callback) {
                callbackList.push(callback);
            }
            // caller needs to wait for template to load, so return null
            return null;
        };
        TemplateService.prototype.handleHttpResult = function (httpResult, url) {
            if (httpResult.status !== 200 || httpResult.response === null) {
                console.warn('Unable to get template error ' + httpResult.status + ' - ' + url);
                return;
            }
            // response success, so process it
            this.templateCache[url] = httpResult.response;
            // inform all listeners that this is now in the cache
            var callbacks = this.waitingCallbacks[url];
            for (var i = 0; i < callbacks.length; i++) {
                var callback = callbacks[i];
                // we could pass the callback the response, however we know the client of this code
                // is the cell renderer, and it passes the 'cellRefresh' method in as the callback
                // which doesn't take any parameters.
                callback();
            }
            if (this.$scope) {
                var that = this;
                setTimeout(function () {
                    that.$scope.$apply();
                }, 0);
            }
        };
        return TemplateService;
    })();

最佳答案

我最终发现了这个问题。 在 IE9 中,模板位于响应内的responseText 上。 在 IE10+ 和所有其他浏览器中,它是响应式的。

所以为了修复它,在上面的代码中,而不是:

     // response success, so process it
     this.templateCache[url] = httpResult.response;

我添加:

     // response success, so process it
     //in IE9 the response is in - responseText
     this.templateCache[url] = httpResult.response || httpResult.responseText;

为了将来引用,在此处添加答案。 与 Angular 无关。 :)

更新: https://github.com/ceolter/ag-grid/issues/521

代码已进入存储库:) 感谢 Niall Crosby(ceolter)。

关于javascript - ag-grid + templateUrl 在 IE9 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33295932/

相关文章:

php - 使用 AJAX 传递 JavaScript 数组

使用 Jquery 的 JavaScript!循环并打印值

javascript - 如何使用 select ng-options 实现有效的空选项

javascript - Angular ui-router 嵌套路由在带有 babel 的 ES6 中不起作用?

html - 仅限 IE 的对象必需错误消息

javascript - 仅允许来自条形码扫描器的文本框输入并限制来自键盘的任何输入

javascript - 寻找适用于 Apple 类型下拉列表/菜单的 CSS

mysql - Mean Stack -> Sequelize Mysql 关联

css - 在 Internet Explorer 9 中使用 CSS 对齐 Div 列表中的文本

internet-explorer - Internet Explorer 10 开发人员工具在某些导航上关闭