gpt4 book ai didi

knockout.js - 意外调用方法或属性访问。仅在 IE8 中

转载 作者:行者123 更新时间:2023-12-04 03:01:36 28 4
gpt4 key购买 nike

以下错误仅在 IE8 中出现...适用于 ChromeFirefox 无法测试 IE9,因为我最近降级了测试目的。

Unexpected call to method or property access.

调用堆栈

相关代码标有\\Call occurs here

来自 IE 调试器的调试值...:
_frames = 对象/函数
回调 = 对象/函数
callbackTarget = 对象/函数
callbackArg = undefined

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);

View 模型

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

msg.d

无法共享真实的 msg.d 但被验证为有效的 JSONJS 对象,并且是一个 array.

更新 1

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

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

最佳答案

在我的具体案例中,问题是“简单”...在使用作为 IE8 运行的 IE9 调试 6 个多小时后,我将 domNode 添加到监视列表中,并且看到它未能 appendChild...我查看了 dom 元素,它是:

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

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

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

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

神速...

关于knockout.js - 意外调用方法或属性访问。仅在 IE8 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18241584/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com