TypeScript -使用knockout.js的JavaScript在IE8中无法工作- Object不支持此属性或

TypeScript - JavaScript using knockout.js not working in IE8 - "Object doesn't support this property or method"

本文关键字:Object 工作 不支持 属性 IE8 js knockout 使用 JavaScript TypeScript      更新时间:2023-09-26

我有这个代码(也显示在下面),这是给我一个错误在IE8,但在Chrome和PhantomJS很好。

错误是"对象不支持此属性或方法knockout-2.2.1.debug.js,第2319行字符35",从currentPage(pages[pages.indexOf(current) + steps]);

调用

我不知道为什么它不工作,所以任何帮助将非常感激!

var Page = (function () {
    function Page(index, name, canNavigateToPage, navigatedToThisPage) {
        this.index = index;
        this.name = name;
        this.canNavigateToPage = canNavigateToPage;
        this.navigatedToThisPage = navigatedToThisPage;
    }
    Page.prototype.navigateToPage = function () {
        if (this.canNavigateToPage()) {
            this.navigatedToThisPage(this);
        }
    };
    return Page;
})();
var AccountSearchParameters = (function () {
    function AccountSearchParameters() {
        this.reference = ko.observable();
        this.scheme = ko.observable();
        this.lastName = ko.observable();
        this.sufficientInputToSearchForAccount = ko.computed(function () {
            return this.reference() && this.scheme() && this.lastName();
        }, this);
    }
    return AccountSearchParameters;
})();
function viewModel() {
    var self = this,
        currentPage = ko.observable(),
        accountSearchParameters = new AccountSearchParameters(),
        forwardPageProgressionGuards = {
            '1': function canMoveToPage2() {
                return accountSearchParameters.sufficientInputToSearchForAccount();
            },
                '2': function canMoveToPage3() {
                return true;
            },
                '3': function canMoveToPage4() {
                return true;
            }
        },
        canMoveToNextPage = function (currentlyOnPage) {
            function disallowPageMovementNotExplicitlyDefined() {
                return false;
            }
            return (forwardPageProgressionGuards[currentlyOnPage] || disallowPageMovementNotExplicitlyDefined)();
        },
        canMoveToPreviousPage = function (currentlyOnPage) {
            return currentlyOnPage > 1;
        },
        pages = [
        new Page(1, 'Customer details', function () {
            return true;
        }, function (page) {
            currentPage(page);
        }),
        new Page(2, 'Bank details', forwardPageProgressionGuards['1'], currentPage),
        new Page(3, 'Payment details', forwardPageProgressionGuards['2'], currentPage),
        new Page(4, 'Confirmation', function () {
            return true;
        }, currentPage)],
        pageNavigator = function (canNavigate, steps) {
            current = currentPage();
            console.log(canNavigate(current.index));
            if (canNavigate(current.index)) {
                currentPage(pages[pages.indexOf(current) + steps]);
            }
        };
    currentPage(pages[0]);
    self.page = ko.computed(function () {
        return currentPage();
    });
    self.accountSearchParameters = accountSearchParameters;
    self.nextPage = function () {
        pageNavigator(canMoveToNextPage, 1);
    };
    self.previousPage = function () {
        pageNavigator(canMoveToPreviousPage, -1);
    };
    self.canMoveToNext = ko.computed(function () {
        return canMoveToNextPage(currentPage().index);
    });
    return self;
}
$(function () {
    ko.applyBindings(viewModel());
});

indexOf在IE8中不支持,使用$.inArray