当执行以下ViewModel函数时,错误 Uncaught TypeError:self.deleteInvisibleColumns不是函数被引发 - 为什么会这样?
function ViewModel(vm) {
var self = this;
this.rows = ko.observableArray(vm.Rows);
self.deleteInvisibleColumns();
this.deleteInvisibleColumns = function () {
for (var i = 0; i < vm.Rows.length; i++) {
var row = vm.Rows[i];
var keys = Object.keys(row);
for (var k = 0; k < keys.length; k++) {
if (vm.VisibleColumns.indexOf(keys[k]) === (-1)) {
delete row[keys[k]];
};
};
};
};
答案 0 :(得分:1)
试试这个:
在callint之前删除函数定义
对函数定义使用“self”并调用它
function ViewModel(vm) {
var self = this;
this.rows = ko.observableArray(vm.Rows);
self.deleteInvisibleColumns = function () {
for (var i = 0; i < vm.Rows.length; i++) {
var row = vm.Rows[i];
var keys = Object.keys(row);
for (var k = 0; k < keys.length; k++) {
if (vm.VisibleColumns.indexOf(keys[k]) === (-1)) {
delete row[keys[k]];
};
};
};
};
self.deleteInvisibleColumns();
};