2

我有一个定义如下的视图模型:

var ViewModel = function() {
    var self = this;
    self.property1 = ko.observable().extend({ required: true });
    self.property2 = ko.computed(function() {
        return self.property1();
    });
    self.form_onsubmit = function (form) {
        if (!self.isValid()) {
            console.log("error");
        }
        return false;
    };
};

$(function () {
    ko.applyBindingsWithValidation(new ViewModel());
});

当我调用该form_onsubmit函数时,发生错误:

TypeError: self.isValid is not a function
if (!self.isValid()) {

怎么解决,谢谢^^^

4

1 回答 1

4

添加

self.errors = ko.validation.group(self);

到您的视图模型

于 2013-09-01T21:31:00.397 回答