0

我正在尝试对我的网格进行排序。下面是我的代码

ko.moveInGrid = {
    // Defines a view model class you can use to populate a grid
    viewModel : function(configuration) {
        this.data = configuration.data;
        this.currentPageIndex = ko.observable(0);
        this.pageSize = configuration.pageSize || 5;

        // If you don't specify columns configuration, we'll use scaffolding
        this.columns = configuration.columns
                || getColumnsForScaffolding(ko.utils
                        .unwrapObservable(this.data));
        this.actions = configuration.actions;

        this.itemsOnCurrentPage = ko.computed(function() {
            var startIndex = this.pageSize * this.currentPageIndex();
            return this.data.slice(startIndex, startIndex + this.pageSize);
        }, this);

        this.maxPageIndex = ko.computed(function() {
            return Math.ceil(ko.utils.unwrapObservable(this.data).length
                    / this.pageSize) - 1;
        }, this);
         this.sortByName = function() {
             console.info(configuration.columns);
             console.log("this works");
             configuration.sort(function(a, b) {
                    return a.name < b.name ? -1 : 1;
                });
            };
    }
};

这就是我如何称呼我的function

<th data-bind=\"click: $root.sortByName,attr:{'data-translate': headerText}\" class=\"sorting\"></th>\

ViewModel的很好。当我点击我的标题时,它会显示以下错误

TypeError: configuration.sort is not a function
4

1 回答 1

0

我看到您要对名称进行排序,我来宾该名称在 viewModel.data 中。所以你可以先在下面的代码测试它的工作

viewModel.data.sort(function(a, b) {
                return a.name < b.name ? -1 : 1;
            });).
于 2014-04-07T09:42:46.953 回答