我有一个定义如下的视图模型:
var ViewModel = function() {
var self = this;
self.name = ko.observable().extend({ required: true });
self.identityCode = ko.observable().extend({ required: true, maxLength: 18, minLength: 15 });
self.gender = ko.computed(function() {
// get gender information from the identiy code here
});
self.birthdate = ko.computed(function() {
// get birthdate information from the identity code here
});
self.form_onsubmit = function (form) {
if (!self.isValid()) {
self.errors.showAllMessages();
return false;
} else {
return true;
}
};
};
正如您在上面的代码中看到的,性别字段和 brithdate 字段是从身份代码中获取的计算字段。我只是想知道如何在做之前获得身份代码的验证结果。谢谢!