0

私は次のように定義されたビューモデルを持っています:

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;
        }
    };
};

上記のコードを見るとわかるように、性別フィールドと生年月日フィールドは、ID コードから取得される計算フィールドです。実行する前に、ID コードの検証結果を取得する方法を知りたいだけです。ありがとう!

4

1 に答える 1

0

検証済みのオブザーバブルは、計算された で拡張されisValidます。したがって、次の方法で結果を確認できます。

    self.gender = ko.computed(function() {
        // get gender information from the identiy code here
        if(self.identityCode.isValid()) {
          // do something with the code
        }
    });
于 2013-03-20T18:58:12.023 に答える