3

以下错误仅发生在IE8...Works inChrome并且Firefox无法测试 IE9,因为我最近出于测试目的降级了。

对方法或属性访问的意外调用。

调用堆栈

标有\\Call的相关代码出现在此处

从 IE 调试器调试值...:
_frames = 对象/函数
回调 = 对象/函数
callbackTarget = 对象/函数
callbackArg = 未定义

ko.dependencyDetection = (function () {
    var _frames = [];

    return {
        begin: function (callback) {
            _frames.push({ callback: callback, distinctDependencies:[] });
        },

        end: function () {
            _frames.pop();
        },

        registerDependency: function (subscribable) {
            if (!ko.isSubscribable(subscribable))
                throw new Error("Only subscribable things can act as dependencies");
            if (_frames.length > 0) {
                var topFrame = _frames[_frames.length - 1];
                if (!topFrame || ko.utils.arrayIndexOf(topFrame.distinctDependencies, subscribable) >= 0)
                    return;
                topFrame.distinctDependencies.push(subscribable);
                topFrame.callback(subscribable);
            }
        },

        ignore: function(callback, callbackTarget, callbackArgs) {
            try {
                _frames.push(null);
                return callback.apply(callbackTarget, callbackArgs || []);
            }
            //Call occurs here
            //Error occurs here since there isn't a catch and the try is failing.
            finally {
                _frames.pop();
            }
        }
    };
})();

来自:

"notifySubscribers": function (valueToNotify, event) {
    event = event || defaultEvent;
    if (this._subscriptions[event]) {
        //Call occurs here
        ko.dependencyDetection.ignore(function() {
            ko.utils.arrayForEach(this._subscriptions[event].slice(0), function (subscription) {
                // In case a subscription was disposed during the arrayForEach cycle, check
                // for isDisposed on each subscription before invoking its callback
                if (subscription && (subscription.isDisposed !== true))
                    subscription.callback(valueToNotify);
            });
        }, this);
    }
},

来自:

ko.observable = function (initialValue) {
    var _latestValue = initialValue;

    function observable() {
        if (arguments.length > 0) {
            // Write

            // Ignore writes if the value hasn't changed
            if ((!observable['equalityComparer']) || !observable['equalityComparer'](_latestValue, arguments[0])) {
                observable.valueWillMutate();
                _latestValue = arguments[0];
                if (DEBUG) observable._latestValue = _latestValue;
                observable.valueHasMutated();
            }
            return this; // Permits chained assignments
        }
        else {
            // Read
            ko.dependencyDetection.registerDependency(observable); // The caller only needs to be notified of changes if they did a "read" operation
            return _latestValue;
        }
    }
    if (DEBUG) observable._latestValue = _latestValue;
    ko.subscribable.call(observable);
    observable.peek = function() { return _latestValue };
    //call occurs here
    observable.valueHasMutated = function () { observable["notifySubscribers"](_latestValue); }
    observable.valueWillMutate = function () { observable["notifySubscribers"](_latestValue, "beforeChange"); }
    ko.utils.extend(observable, ko.observable['fn']);

    ko.exportProperty(observable, 'peek', observable.peek);
    ko.exportProperty(observable, "valueHasMutated", observable.valueHasMutated);
    ko.exportProperty(observable, "valueWillMutate", observable.valueWillMutate);

    return observable;
}

来自:

ko.observable = function (initialValue) {
    var _latestValue = initialValue;

    function observable() {
        if (arguments.length > 0) {
            // Write

            // Ignore writes if the value hasn't changed
            if ((!observable['equalityComparer']) || !observable['equalityComparer'](_latestValue, arguments[0])) {
                observable.valueWillMutate();
                _latestValue = arguments[0];
                if (DEBUG) observable._latestValue = _latestValue;
                //Call occurs here
                observable.valueHasMutated();
            }
            return this; // Permits chained assignments
        }
        else {
            // Read
            ko.dependencyDetection.registerDependency(observable); // The caller only needs to be notified of changes if they did a "read" operation
            return _latestValue;
        }
    }
    if (DEBUG) observable._latestValue = _latestValue;
    ko.subscribable.call(observable);
    observable.peek = function() { return _latestValue };
    observable.valueHasMutated = function () { observable["notifySubscribers"](_latestValue); }
    observable.valueWillMutate = function () { observable["notifySubscribers"](_latestValue, "beforeChange"); }
    ko.utils.extend(observable, ko.observable['fn']);

    ko.exportProperty(observable, 'peek', observable.peek);
    ko.exportProperty(observable, "valueHasMutated", observable.valueHasMutated);
    ko.exportProperty(observable, "valueWillMutate", observable.valueWillMutate);

    return observable;
}

来自:

self.fraudQueue(msg.d);

视图模型

function FraudQueueViewModel(runDate, analyst, fraudOid, runNumber, processed, parameter) {
    var self = this;
    self.fraudQueue = ko.observableArray();
    \\...

味精

不能共享 truemsg.d但被验证为有效JSONand JS object, and 是array.

更新 1

错误似乎出现在msg.d...的内部数组上,msg.d其中包含 18 个内部arraysobjects,其中一些包含另一个内部的array

我创建了这个jsFiddle来演示这个问题,但甚至无法让 IE8 打开jsFiddle

4

2 回答 2

5

在我的具体情况下,问题是“简单的” ......在使用 IE9 以 IE8 运行 6 小时以上进行调试后,我将其添加domNode到了观察列表中,发现它未能appendChild...我查看了 dom 元素,它是A:

<td data-bind="text: viewModel.functionName(property)"></td>

我所做的只是将此绑定更改为以下内容:

<td>
    <span data-bind="text: viewModel.functionName(property)"></span>
</td>

function text显然 IE8在双嵌套foreach循环内绑定元素存在问题。我不确定这是否对其他人有帮助,但重要的部分是在 IE8 模式下使用 IE9 调试问题。这允许您使用Add to watch允许您查看对象的属性...然后查找它失败的节点,并猜测和祈祷

神速...

于 2013-08-15T18:21:14.197 回答
1

正如通过与 abc123 类似的情况所经历的那样,在 IE8 中,您使用的任何 HTML5 元素都不能绑定文本元素。对于许多元素,我最终不得不用旧的 div/span 标签替换 html5 标签,因为它不会绑定到“文本”。

于 2014-10-23T22:33:26.667 回答