IE8 Knockout 3.3.0错误

时间:2015-06-24 14:41:29

标签: javascript knockout.js internet-explorer-8

我不确定导致它的原因,但IE8指向此代码中的catch行导致错误,导致页面无法加载。我真的没有更多关于导致它的原因的线索。我甚至用引号包装了任何保留的关键字,以避免在淘汰赛中发生冲突。

ko.utils.arrayForEach(orderedBindings, function(bindingKeyAndHandler) {
    // Note that topologicalSortBindings has already filtered out any nonexistent binding handlers,
    // so bindingKeyAndHandler.handler will always be nonnull.
    var handlerInitFn = bindingKeyAndHandler.handler["init"],
        handlerUpdateFn = bindingKeyAndHandler.handler["update"],
        bindingKey = bindingKeyAndHandler.key;

    if (node.nodeType === 8) {
        validateThatBindingIsAllowedForVirtualElements(bindingKey);
    }

    try {
        // Run init, ignoring any dependencies
        if (typeof handlerInitFn == "function") {
            ko.dependencyDetection.ignore(function() {
                var initResult = handlerInitFn(node, getValueAccessor(bindingKey), allBindings, bindingContext['$data'], bindingContext);

                // If this binding handler claims to control descendant bindings, make a note of this
                if (initResult && initResult['controlsDescendantBindings']) {
                    if (bindingHandlerThatControlsDescendantBindings !== undefined)
                        throw new Error("Multiple bindings (" + bindingHandlerThatControlsDescendantBindings + " and " + bindingKey + ") are trying to control descendant bindings of the same element. You cannot use these bindings together on the same element.");
                    bindingHandlerThatControlsDescendantBindings = bindingKey;
                }
            });
        }

        // Run update in its own computed wrapper
        if (typeof handlerUpdateFn == "function") {
            ko.dependentObservable(
                function() {
                    handlerUpdateFn(node, getValueAccessor(bindingKey), allBindings, bindingContext['$data'], bindingContext);
                },
                null,
                { disposeWhenNodeIsRemoved: node }
            );
        }
    } catch (ex) {
        ex.message = "Unable to process binding \"" + bindingKey + ": " + bindings[bindingKey] + "\"\nMessage: " + ex.message;
        throw ex;
    }
});

1 个答案:

答案 0 :(得分:1)

如果您在项目中使用过 Knockout.js ,则有时可能会遇到以下错误“ Uncaught ReferenceError:无法处理绑定”。最可能的原因是某个地方的错字或忘记更改上下文。您处于foreach绑定中,而忘记使用$ parent。

这可能会导致进一步的innerHtml错误,从而导致页面无法加载js。