我正在嘗試使用knockout.validation插件。我創建了一個exampleViewModel:如何使用ko.validation.group函數
function exampleViewModel() {
this.P1 = ko.observable().extend({ required : true });
this.P2 = ko.observable().extend({ required : true });
this.P3 = ko.observable().extend({ required : true });
this.P4 = ko.observable().extend({ required : true });
this.errors = ko.validation.group(this);
}
在我創建驗證組命名錯誤當前對象上述視圖模型。現在,如果任何驗證規則在4個以外的任何一個屬性上失敗,則此錯誤屬性包含錯誤消息。
My question is
,如果我想創建只有3個屬性(P1, P2, P3)
的驗證組開出4比我該怎麼辦呢?
用這種方法來調試迪朗達爾可觀察插件驗證問題。 'this.errors = ko.validation.group({P1:observable(this,'P1')});'我相信它應該檢測到getter/setter並作出相應的反應,但是這至少證明了驗證有效。 – MrYellow