Durandal 杜兰达尔IE8“;未定义为空或不是对象;viewEngine.js中出现错误

Durandal 杜兰达尔IE8“;未定义为空或不是对象;viewEngine.js中出现错误,durandal,durandal-2.0,Durandal,Durandal 2.0,我只在IE中得到上述错误。 抛出错误的行显然是 element.setAttribute('data-view', viewId); 在viewEngine.js中 createView: function(viewId) { var that = this; var requirePath = this.convertViewIdToRequirePath(viewId); var existing = this.tryGetViewFromC

我只在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(markup)没有像它应该返回的那样返回HtmlLevel,并且通常对所有其他模块都返回HtmlLevel…

看起来IE8与setAttribute方法有问题

要解决此问题,请尝试以下操作:

将此用作您的doctype

<!DOCTYPE html>

然后把这个放在文件的开头

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


资源链接:

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

谢谢你的建议。我确实在index.html中设置了这些标记。除此之外,该脚本还可以与我的应用程序的其他模块配合使用。如果我的帖子有误导性,并且我没有发布模块本身的任何代码,我很抱歉。我会编辑我的帖子。我发布的第一行是我在下面发布的Durandal核心文件viewEngine.js的一部分。这个解决方案对我很有用。我只是放置了一个没有任何html标记的文本,因此viewEngine无法将其解析为html