0

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

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

如何重现:

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

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

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

编辑:

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

无限循环是:getTemplate,(排队等待,直到调用结束),调用结束,模板添加到缓存,运行回调,回调在模板缓存中没有看到模板,创建另一个回调,将其添加到队列中,等等上。(来自下面的 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;
    })();
4

1 回答 1

1

我最终发现了这个问题。在 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

代码进入了 repo :) 感谢 Niall Crosby (ceolter)。

于 2015-10-23T09:30:28.040 回答