好的,所以我终于弄清楚了我的代码的哪一部分导致了异常。你可以在这里阅读最初的帖子。初始帖子中的代码缺少实际导致异常的部分(手动订阅viewPortData
observable)。显然,我以某种方式做错了......这是代码:
self.viewPortData = ko.observable();
self.viewPortData.subscribe(function (newValue) {
var viewPort = $('#metro-view-port');
if (viewPort && newValue) {
self.fadeInOut(viewPort, newValue);
}
});
self.fadeInOut = function (domObject, newContent) {
if (newContent) {
var currentContent = domObject.html();
if (currentContent) {
var wrappedContent = $(currentContent);
wrappedContent.fadeOut(400, function () {
wrappedContent.empty();
domObject.html(newContent).hide().fadeIn(400);
});
} else {
domObject.html(newContent).hide().fadeIn(400);
}
}
};
那么我哪里做错了?