杜兰达尔 IE8 在 viewEngine 中"undefined is null or not an object"错误.js



我只在IE中得到上述错误。抛出错误的行显然是

element.setAttribute('data-view', viewId);
在viewEngine.js

createView: function(viewId) {
        var that = this;
        var requirePath = this.convertViewIdToRequirePath(viewId);
        var existing = this.tryGetViewFromCache(requirePath);
        if (existing) {
            return system.defer(function(dfd) {
                dfd.resolve(existing.cloneNode(true));
            }).promise();
        }
        return system.defer(function(dfd) {
            system.acquire(requirePath).then(function(markup) {
                var element = that.processMarkup(markup);
                element.setAttribute('data-view', viewId);
                that.putViewInCache(requirePath, element);
                dfd.resolve(element.cloneNode(true));
            }).fail(function(err) {
                that.createFallbackView(viewId, requirePath, err).then(function(element) {
                    element.setAttribute('data-view', viewId);
                    that.cache[requirePath] = element;
                    dfd.resolve(element.cloneNode(true));
                });
            });
        }).promise();
    },

编辑:我将其缩小到生命周期中activate()和binding()之间发生的错误。我不确定这是否有任何帮助。

edit2:经进一步调查,我发现processMarkup(标记)不返回HtmlDivElement像它应该和通常做的所有其他模块…

看起来IE8的setAttribute方法有问题。

解决方法如下:

使用这个作为你的doctype

<!DOCTYPE html>

然后把它放在文档的头部

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

资源链接:用IE兼容的脚本替换setAttribute

我发现了错误,它不是任何javascript代码的一部分。Durandals viewEngine.js中的$. parsehtml()函数只有在提供的html标记具有语法正确的html标记时才返回对象。我忘记在视图的最后关闭一个div,这就是问题所在

相关内容

最新更新